<?php 

/*
 * Nguoi tao: HUNGVM 
 * Ngay tao: 18/11/2008
 * Noi dung: Tao lop Efy_Publib_Library luu cac ham dung chung
 */
require_once 'Efy/Init/Config.php';
abstract class Efy_Publib_Library {	
	
	
	
	/*
	 * Creater : HUNGVM
	 * Date : 16/06/2010
	 * Idea : Tao phuong thuc khoi tao gia tri luu trong Cookie
	 *
	 * @param $sName : Ten Cookie
	 * @param $sValue : Gia tri luu trong Cookie
	 */
	public static function _createCookie($sName,$sValue = ""){ 
		//Dat gia tri expires
		$dExpires = time() + 60*60*24; 
		//Dat gia tri vao Cookie
		setcookie($sName, $sValue, $dExpires,"/",""); 
	} 
	
	/*
	 * Creater : HUNGVM
	 * Date : 16/06/2010
	 * Idea : Tao phuong thuc lay gia tri luu trong Cookie voi $sNname tuong ung
	 *
	 * @param $sNname : Ten Cookie
	 * @return Gia tri luu trong Cookie, neu chua ton tai return false
	 */
	public static function _getCookie($sNname){ 
		if (isset($_COOKIE[$sNname]) && strlen($_COOKIE[$sNname])>0 ) { 
			return urldecode($_COOKIE[$sNname]); 
		}else{ 
			return ""; 
		} 
	
	}
	/*
	********************************************************************************
	Ten ham		:_xmlStringToArray
	Chuc nang	: Chuyen doi mot xau XML thanh mot array
	Tham so: $p_xmlstring - la xau XML can chuyen doi. Xau XML nay chi co 2 cap, vi du
	Cach su dung:
	- Truoc khi goi ham nay, phai khai bao cac bien sau:
	+ $p_arr_items: la array ket qua
	+ $p_level1_tag_name: ten tag dau tien cua xau XML (trong vi du tren thi $p_level1_tag_name=staff_list)
	+ $p_level2_tag_name_list: danh sach tag can chuyen gia tri vao array: (trong vi du tren thi $p_level1_tag_name="id,code")
	+ $p_delimitor: ki tu phan cach cac phan tu cua $p_level2_tag_name_list
	********************************************************************************
    */
	public static function _xmlStringToArray($xmlData){		
		global $p_arr_items,$p_level1_tag_name, $p_level2_tag_name_list, $p_delimitor;
		
		//Tao doi tuong de doc du lieu dang XML
		$objXML = new SimpleXMLElement($xmlData); 
		
		//Lay du lieu tu phan tu $p_level1_tag_name
		$result = $objXML->xpath($p_level1_tag_name);

		
		//Chuyen cac phan tu cua xau -> mang mot chieu
	   	$arr_node = explode($p_delimitor,$p_level2_tag_name_list);
	   	
	   	//So phan tu cua mang
	   	$count = 0;
	   	
	   	//Chuyen doi du lieu tu XML -> array theo chuan array[index][node] trong do
	   	//index: La chi so cua array; node : La cac then trong xau XML
		
		foreach($result as $xmlValue){
			for($index = 0;$index < sizeof($arr_node);$index++){
				$p_arr_items[$count][$arr_node[$index]] = (string)$xmlValue->$arr_node[$index];				
			}
	    	$count++; //Tang so phan tu cua mang len
	    }
	    	    
		return $p_arr_items;
	}

	/*
	 * ******************************************************************************************************************
	 * @Idea   :Lay id goc cua don vi (phong ban) cha
	 * @return : Id cua thu muc goc
	 ********************************************************************************************************************* 
	 */
	public static function _getRootUnitId($p_arr=array()){
		$v_root_id = "";
		
		//Lay thong tin cac phong ban	
		$arr_all_unit = $p_arr;
		$arr_all_unit = str_replace('\n','',$arr_all_unit);
		//var_dump($arr_all_unit);
		foreach ($arr_all_unit as $v_unit){			
			if (is_null($v_unit['parent_id']) || trim($v_unit['parent_id']) == '' || trim($v_unit['parent_id']) == 'NULL'){
				$v_root_id = $v_unit['id']; //Don vi goc 
				break;
			}
			unset($v_unit);	
		}
		return $v_root_id;
	}		
	
	/*
	 * Creater : HUNGVM
	 * Date :
	 * Idea : copy file $pToFile vao thu muc chi dinh$pFromFile
	 *
	 * @param $pFromFile : Duong dan luu file
	 * @param $pToFile : Ten file chua noi dung
	 */
	public static function _copyFile($pFromFile, $pToFile){		
		//Goi ham copy file cua he thong PHP
		move_uploaded_file ($pFromFile,$pToFile);
	}	
		
	/*
	 * Creater : HUNGVM
	 * Date : 09/01/2009
	 * Idea: Doc file
	 * @param $spFilePath : Duong dan file can doc
	 * @return Noi dung file
	 */
	public static function _readFile($spFilePath){
		$spRet = "";
		$handle = fopen($spFilePath,"r");
		if($handle){
			while(!feof($handle)){
				$spRet .= fread($handle,10000);
			}
		}
		return $spRet;
	}	

	/**
	 * Creater : HUNGVM
	 * Date : 09/01/2009
	 * Idea: Ghi file
	 * @param $spFilePath : Duong dan file can ghi
	 * @param $spContent : Noi dung can ghi vao file
	 */
	public static function _writeFile($spFilePath, $spContent){		
		if (file_exists($spFilePath)) {
		   chmod($spFilePath,0777);	
		}
		$handle = fopen ($spFilePath, "w+");
		if ($handle){
			fwrite($handle, $spContent);
			fclose($handle);
		}	
		//echo $handle;exit;
	}	

	/**
	 * Creater : HUNGVM
	 * Date : 21/05/2009
	 * Idea : Tao phuong thuc xoa file trong thu muc $sPathDir
	 *
	 * @param $sFileNameList : Danh sach file can xoa
	 * @param $sDelimitor    : Ky tu phan tach giua cac phan tu
	 * @param $sPathDir		 : Duong dan luu file can xoa
	 */
	public function _deleteFile($sFileNameList, $sDelimitor, $sPathDir){
 		$arrFileName = explode($sDelimitor,$sFileNameList); //Mang luu ten file
    	$iCount = sizeof($arrFileName);		
		for($index = 0; $index < $iCount; $index++){
			$sFullPathFileName =  $sPathDir . $arrFileName[$index];
			if(file_exists($sFullPathFileName)){ 
				if(is_writable($sFullPathFileName)){
					unlink($sFullPathFileName);					
				}else{		
					echo "<font color='red'> <b>File $arrFileName[$index]: can xoa khong cho phep truy cap!</b></font> <br /> ";				
				}
			}else{
				echo "<font color='red'> <b>File $arrFileName[$index]: can xoa khong ton tai trong :" . $sPathDir . "</b></font> <br /> ";				
			}	
		}			
	 }
	/**
	 * Idea: Sinh ra doan ma HTML the hien cac option cuar mot SelectBox 
	 *
	 * @param + $arr_list : mang du lieu
	 * @param + $IdColumn : Ten cot lay gia tri gan cho moi option
	 * @param + $ValueColumn
	 * @param $NameColumn  : Ten cot lay de hien thi cho moi option
	 * @param $SelectedValue : Gia tri duoc lua chon
	 * @return Chuoi HTML hien thi selectbox
	 */
	
	public static function _generateSelectOption($arr_list,$IdColumn,$ValueColumn,$NameColumn,$SelectedValue){
		$strHTML = "";
		$i=0;
		$count=sizeof($arr_list);
		for($row_index = 0;$row_index< $count;$row_index++){
			$strID=trim($arr_list[$row_index][$IdColumn]);
			$strValue=trim($arr_list[$row_index][$ValueColumn]);
			$gt=$SelectedValue;
			if($strID != $SelectedValue) {
				$optSelected="";
			} else {
				$optSelected="selected";
			}
			$DspColumn=trim($arr_list[$row_index][$NameColumn]);
			$strHTML.='<option id='.'"'.$strID.'"'.' '.'name='.'"'.$DspColumn.'"'.' ';
			$strHTML.='value='.'"'.$strValue.'"'.' '.$optSelected.'>'.$DspColumn.'</option>';
			$i++;
		}
		return $strHTML;
	}

    public static function _generateSelectOptionTab($arr_list,$IdColumn,$ValueColumn,$NameColumn,$SelectedValue){
        $strHTML = "";
        $i=0;
        $count=sizeof($arr_list);
        for($row_index = 0;$row_index< $count;$row_index++){
            $strID=trim($arr_list[$row_index][$IdColumn]);
            $strValue=trim($arr_list[$row_index][$ValueColumn]);
            $gt=$SelectedValue;
            if($strID != $SelectedValue) {
                $optSelected="";
            } else {
                $optSelected="selected";
            }
            $DspColumn=trim($arr_list[$row_index][$NameColumn]);
            $strHTML.='<option id='.'"'.$strID.'"'.' '.'name='.'"'.$DspColumn.'"'.' ';
            $strHTML.='value='.'"'.$strValue.'"'.' '.$optSelected.'>'.$DspColumn.'</option>';
            $i++;
        }
        return $strHTML;
    }
	
	/*
	 * Thay the cac ki tu dac biet trong mot xau boi ki tu khac
	 *
	 * @param $p_string : Chuoi can thay the
	 * @return : Chuoi da thay the ky tu
	 */	
	public static function _replaceBadChar($spString) {
		$psRetValue = stripslashes($spString);
		$psRetValue = str_replace('&','&amp;', $psRetValue);
		$psRetValue = str_replace('<','&lt;', $psRetValue);
		$psRetValue = str_replace('>','&gt;',$psRetValue);
		$psRetValue = str_replace('"','&#34;', $psRetValue);
		$psRetValue = str_replace("'",'&#39;', $psRetValue);		
		return $psRetValue;
	}
	
	/*
	 * Lay gia tri lon nhat cua mot cot trong mot table va cong them 1
	 *
	 * @param unknown_type $p_table
	 * @param unknown_type $p_column
	 * @param unknown_type $p_where_clause
	 * @return unknown
	 */	
	public static function _getNextValue($psTable, $psColumn, $psWhereClause){
		global $adoConn;
		Zend_Loader::loadClass('Efy_Db_Connection');
		$objConn = new Efy_DB_Connection();
		
		$cmd = "Select max(" . $psColumn . ")" . " MAX_VALUE " . " From " . $psTable ;
		if (!is_null(trim($psWhereClause)) and trim($psWhereClause)<>""){
			$cmd = $cmd . " Where " . $psWhereClause ;
		}
		
		//Thuc hien cau lenh SQL
		$arrResult = $objConn->adodbQueryDataInNameMode($cmd);
						
		//Lay gia tri thu tu hien tiep theo
		$piNextValue = $arrResult[0]['MAX_VALUE'];
		if (!is_null($piNextValue)){
			$piNextValue = intval($piNextValue)+1;
		}else{
			$piNextValue = 1;
		}		
		return $piNextValue;
	}	
	
	/**
	 * tra lai gia tri true neu DB hien thoi la SQL-SERVER
	 *
	 * @return unknown
	 */	
	public static function _isSqlserver(){
		global $_ISA_DB_TYPE;
		return ($_ISA_DB_TYPE == "SQL SEVER");
	}
	
	/**
	 * Creater : HUNGVM
	 * Date: 11/01/2009
	 * Idea: Tao mang mot chieu, mang co cau truc cac phan tu theo kieu
	 * array(pt1=>pt2, pt3=>pt4)
	 *
	 * @param $pArraySource : Mang chua du lieu can lay thong tin de tao mang mot chieu
	 * @param $psColumName01 : Ten cot (VD: PK_)
	 * @param $psColumName02 : : Ten cot (VD: C_NAME)
	 * @return Mang mot chieu
	 */
	public static function _createOneDimensionArray($pArraySource, $psColumName01, $psColumName02){
		$arrResultArray = array();			
		if (is_array($pArraySource) && sizeof($pArraySource) > 0){
			//Duyet cac phan tu cua mang
			for($index = 0;$index < sizeof($pArraySource);$index++){				
				// Lay gia tri cua $psColumName01
				$psColumName01Value 		= $pArraySource[$index][$psColumName01];					
				// Lay gia tri cua $psColumName02
				$psColumName02Value 		= $pArraySource[$index][$psColumName02];
				//Chuyen cac phan tu vao mang
				$arrResultArray[$psColumName01Value] = $psColumName02Value;
			}
		}
		return $arrResultArray;
	}
	
	/**
	 * Thay the ky tu thong thuong bang ky tu dac biet
	 *
	 * @param $pshtml : Xau can thay the
	 * @return Xau da duoc thay the
	 */
	public static function _restoreXmlBadChar($pshtml){
		$pshtml = str_replace('&amp;','&',$pshtml);
		$pshtml = str_replace('&quot;','"',$pshtml);
		$pshtml = str_replace('&#39;',"'",$pshtml);
		$pshtml = str_replace('&lt;','<',$pshtml);
		$pshtml = str_replace('&gt;','>',$pshtml);
		$pshtml = str_replace('&#34;','"',$pshtml);
		$pshtml = htmlspecialchars($pshtml);
	return $pshtml;
	echo '$pshtml = '.$pshtml;
	}
	
	/**
	 * Creater: HUNGVM
	 * Date: 12/01/2009
	 * 
	 * @Idea: Thay the ky tu dac biet trong xau XML
	 *
	 * @param $psHtml : Xau can thay the
	 * @return CHuoi duoc thay the cac ky tu dac biet
	 */
	public static function _replaceXmlBadChar($psHtml){
		$psHtml = stripslashes($psHtml);
		$psHtml = str_replace('&','&amp;',$psHtml);
		$psHtml = str_replace('"','&quot;',$psHtml);
		$psHtml = str_replace('<','&lt;',$psHtml);
		$psHtml = str_replace('>','&gt;',$psHtml);
		$psHtml = str_replace("'",'&#39;', $psHtml);
		return $psHtml;
	}
	
	
	/**
	 * Idea: chuyen doi thoi gian dang chuoi yyyymmdd thanh chuoi dang dd/mm/yyyy
	 *
	 * @param $psYyymmdd: la thoi gian dang chuoi
	 * @return Chuoi dang dd/mm/yyyy(De hien thi tren man hinh)
	 */	
	public static function _yyyymmddToDDmmyyyy($psYyymmdd) {
		//echo '<br>xx:'.$psYyymmdd;
		if (is_null($psYyymmdd) || trim($psYyymmdd) == "" || $psYyymmdd ==1900)		
		return "";
		return date("d/m/Y", strtotime($psYyymmdd));
	}
	
	/**
	 * Idea: chuyen doi thoi gian dang chuoi yyyymmdd thanh chuoi dang dd/mm/yyyy hh:mm
	 *
	 * @param $psYyyymmdd : la thoi gian dang chuoi
	 * @return chuoi dang dd/mm/yyyy hh:mm (De hien thi tren man hinh)
	 */	
	public static function _yyyymmddToDDmmyyyyhhmm($psYyyymmdd) {
		if (is_null($psYyyymmdd) || trim($psYyyymmdd) == "")
			return "";
		return date("d/m/Y H:i", strtotime($psYyyymmdd));
	}
	
	/**
	 * Idea: chuyen doi thoi gian dang yyyymmdd thanh chuoi dang dd/mm/yyyy hh:mm:ss
	 *
	 * @param $psYyyymmdd :la thoi gian dang chuoi
	 * @return chuoi dang dd/mm/yyyy hh:mm:ss (De hien thi tren man hinh)
	 */	
	public static function _yyyymmddToDDmmyyyyhhmmss($psYyyymmdd) {
		if (is_null($psYyyymmdd) || trim($psYyyymmdd) == "")
			return "";
		return date("d/m/Y H:i:s", strtotime($psYyyymmdd));
	}
	
	/**
	 * Idea: chuyen doi thoi gian dang yyyymmdd thanh chuoi dang yyyy-mm-dd hh:mm:ss
	 *
	 * @param $psYyyymmdd : la thoi gian dang chuoi
	 * @return chuoi dang dd/mm/yyyy hh:mm:ss (De hien thi tren man hinh)
	 */	
	public static function _yyyymmddToYYyymmddhhmmss($psYyyymmdd) {
		if (is_null($psYyyymmdd) || trim($psYyyymmdd) == "")
			return "";
		return date("Y/m/d H:i:s", strtotime($psYyyymmdd));
	}
	
	/**
	 * Idea: chuyen doi thoi gian dang yyyymmdd thanh chuoi dang hh:mm
	 *
	 * @param $psYyyymmdd : la thoi gian dang chuoi
	 * @return chuoi hh:mm(De hien thi tren man hinh)
	 */	
	public static function _yyyymmddToHHmm($psYyyymmdd) {
		if (is_null($psYyyymmdd) || trim($psYyyymmdd) == "")
			return "";
		return date("H:i", strtotime($psYyyymmdd));
	}
	
	/**
	 * Idea: chuyen doi thoi gian dang chuoi yyyymmdd thanh chuoi dang hh:mm:ss
	 *
	 * @param $psYyyymmdd : la thoi gian dang yyyymmdd
	 * @return chuoi hh:mm:ss (De hien thi tren man hinh)
	 */	
	public static function _yyyymmddToHHmmss($psYyyymmdd) {
		if (is_null($psYyyymmdd) || trim($psYyyymmdd) == "")
			return "";
		return date("H:i:s", strtotime($psYyyymmdd));
	}
	
	/**
	 * @Idea : chuyen doi ngay dang mm/dd/yyyy thanh ngay dang yyyy/mm/dd
	 *
	 * @param $psDdmmyyyy : la chuoi dang dd/mm/yyyy( chuoi chu khong phai date object )
	 * @return chuoi dang yyyy/mm/dd(De dua vao csdl)
	 */	
	public static function _ddmmyyyyToYYyymmdd($psDdmmyyyy) {
		$psdate = NULL;
		$psdateArr = "";
		$psdel = "";
		if(strlen($psDdmmyyyy)==0 or is_null($psDdmmyyyy)) {
			$psdate = "";
		return $psdate;
		}
		if(strpos($psDdmmyyyy,"-")<=0 and strpos($psDdmmyyyy,"/")<=0) {
			$psdate = "";
		return $psdate;	
		}
		if(strpos($psDdmmyyyy,"-")>0) { 
				$psdel = "-";
		}
		if(strpos($psDdmmyyyy,"/")>0) {
				$psdel = "/";
		}
		$arr=explode(" ",$psDdmmyyyy);
		if($arr[0] <> "") {
			$psdateArr = explode($psdel,$arr[0]);
			if(sizeof($psdateArr)<>3) {
				$psdate = NULL;
				return $psdate;	
			} else {
				$psdate = $psdateArr[2]."/".$psdateArr[1]."/".$psdateArr[0].' '.gmdate("H:i:s", time() + 3600*(7+date("0")));
				return $psdate;	
			}
		}
		return $psdate;
	}
	
	/**
	 * @Idea: Lay mot phan tu cua danh sach tai mot vi tri cho truoc
	 *
	 * @param $pList : Mang luu danh sach phan tu
	 * @param $pIndex : Chi so phan tu can lay
	 * @param $pDelimitor : Ky tu phan cach giua cac phan tu
	 * @return Gia tri phan tu lay duoc
	 */	
	public static function _listGetAt($pList,$pIndex,$pDelimitor) {
		$retValue = "";
		if (strlen($pList) == 0){
			return $retValue;
		}
		$arrElement = explode($pDelimitor,$pList);
		$retValue = $arrElement[$pIndex];
		return $retValue;
	}
	
	/**
	 * @Idea : Lay tong so phan tu cua mot danh sach
	 *
	 * @param $pString : Xau ky tu
	 * @param $pDelimitor : Ky tu phan tach cac phan tu
	 * @return So phan tu trong xau phan tach nhau boi $pDelimitor
	 */	
	//*************************************************************************
	public static function _listGetLen($pString, $pDelimitor){
		$retValue =0;
		if(strlen($pString) <> 0){
			$array = explode($pDelimitor, $pString);
			$retValue = sizeof($array);
		}
		return  $retValue;
	}
	
	/**
	 * Creater: HUNGVM
	 * Date: 02/02/2009
	 * IDea: Tao mot chuoi HTML mo ta SelectBox danh sach cac trang (Trang 1; Trang 2;...)
	 *
	 * @param $piTotalRecord : Tong so trang
	 * @param $piCurrentPage : Trang hien thoi
	 * @param $piNumberRecordOnList : So ban ghi / trang
	 * @param $pAction : Thuc hien Action
	 * @return CHuoi html
	 */
	public static function _generateNumberPageIntoSelectbox($piTotalRecord, $piCurrentPage, $piNumberRecordOnList, $pAction){
		$psHtmlString = "";
		//Hien thi SelectBox Tong so trang
		if ($piTotalRecord % $piNumberRecordOnList == 0){
			$psNumberPage = (int)($piTotalRecord / $piNumberRecordOnList);
		}else{
			$psNumberPage = (int)($piTotalRecord / $piNumberRecordOnList)+1;		
		}
		$psHtmlString = $psHtmlString . "Tổng số &nbsp;" . $psNumberPage . "&nbsp;trang.&nbsp;&nbsp;Xem &nbsp;" . "<select class='textbox' name='sel_page' optional='true' style='width:auto' title='Ch&#7885;n trang mu&#7889;n xem' style='width:40'" . "onChange='page_onchange(this,\"" . $pAction ."\")';" . "onKeyDown='change_focus(document.forms[0],this)' >";
		for ($index = 1; $index <= $psNumberPage; $index++){				
			if ($piCurrentPage == $index){
				$psSelect = " selected ";
			}else{
				$psSelect = " ";
			}
			$psHtmlString = $psHtmlString . "<option id='' value='$index' name='$index' $psSelect> " . "Trang &nbsp;" . $index  . "</option>";
		}
		$psHtmlString = $psHtmlString . "</select>";
		
		//Return		
		return $psHtmlString;
	}
	
	/*
	 * Creater: HUNGVM
	 * Date: 03/02/2009
	 * Idea: Tao SelectBox quy dinh so Record / page
	 *
	 * @param $piValue : Gia tri lua chon trong SelectBox
	 * @param $pAction : Action can thuc hien
	 * @return Xau HTML
	 */
	public static function _generateChangeRecordNumberPage($piValue, $sLabel = ""){		
		$psHtmlString = "";	
		//Chuyen doi thong tin trong xau XML -> Mang
		$arrListItem = Efy_Function_RecordFunctions::getAllObjectbyListCode('','DM_SO_HS_TREN_TRANG');		
		//Tao chuoi HTML
		$psHtmlString = $psHtmlString . "Hiển thị ";
		$psHtmlString = $psHtmlString . "<select class='textbox' id = 'cbo_nuber_record_page' name='cbo_nuber_record_page' optional='true' style='width:60' onChange='changeNumberRowPerPage(this)' >";
		$psHtmlString = $psHtmlString . Efy_Library::_generateSelectOption($arrListItem, 'C_CODE', 'C_CODE', 'C_NAME', $piValue);
		$psHtmlString = $psHtmlString . "</select>";
		$strlabel = '';	
		if ($sLabel != ""){
			$strlabel = " $sLabel/1 trang";
		}else{
			$strlabel = " hồ sơ/1 trang";
		}
		$psHtmlString = $psHtmlString . $strlabel;		
		return $psHtmlString;
	}
	
	
	/*
	 * Creater: Thainv
	 * Date: 04/02/2009
	 * Idea: Load tat ca cac file js hoac css 
	 *
	 * @param : $psModuleName : Ten module can load het
	 * @param : $psModuleNameOrther :Lay them cac file o module khac
	 * @param : $parrFileName: Cac file can lay o module khac
	 * @param : $psDelimitor: ky tu ngan cach giua cac file can lay o module khac
	 * @param : $psExtension: Duoi mo rong cua file can lay
	 * @return: Xau HTML
	 */
	public static function _getAllFileJavaScriptCss($psModuleName,$psModuleNameOrther = "" ,$parrFileName = "",$psDelimitor = ",",$psExtension){		
		// Duong dan thu muc doc file
		$sDir = null;		
		// chuoi ket qua tra ve
		$sResHtml = null;
		
		// Zend_Loader::loadClass(Efy_Init_Config);
		$objInitConfif  = new Efy_Init_Config();
		
		//
		$filetype = strtolower($psExtension);
		// thuc hien lay tren tung module cu the
		if($psModuleName != ""){
			//
			$sDir = $psModuleName.'/';		
			
			if (is_dir($sDir)) {				
			    if ($dh = opendir($sDir)) {
			    	
			        while (($file = readdir($dh)) !== false) {			        			        	
			        							
			        	//Thuc hien include file JavaScript	
			        	$filetypeinDirJs = substr($file,strlen($file)-2,2);			        	
		        		$filetypeinDirJs = strtolower($filetypeinDirJs);		        		
			        			        	
			        	if($filetype == "js" && $filetypeinDirJs =="js" ){		
			        		
			        		$sDirFull = $objInitConfif->_setWebSitePath().$sDir.$file;			        		
			            	$sResHtml = $sResHtml.  "<script src=\" ".$sDirFull. " \" type=\"text/javascript\"></script>" . "\n";            	
			        	}	
			        	
			        	//Thuc hien include file Css
			        	$filetypeinDirCss = @substr($file,strlen($file)-3,3);			        	
		        		$filetypeinDirCss = @strtolower($filetypeinDirCss);	
			        	if($filetype == "css" && $filetypeinDirCss =="css"){			        		
			        		$sDirFull = $objInitConfif->_setWebSitePath().$sDir.$file;	            				        		
			            	$sResHtml = $sResHtml.  "<link href=\" " .$sDirFull." \" rel=\"stylesheet\" />" . "\n";            	
			        	}	
			        }
			        closedir($dh);
			    }
			}
		}
		
		// Thuc hien lay file js o nhung module khac		
		if($psModuleNameOrther!= ""){
			//
			$sDir =  $psModuleNameOrther .'/';
        	
			//			
        	$arrTemp = explode($psDelimitor,$parrFileName);
        	
        	for($index =0 ; $index < sizeof($arrTemp); $index++){
        		
        		//Thuc hien include file JavaScript	
	        	$filetypeinDirJs = @substr($arrTemp[$index],strlen($file)-2,2);			
        		$filetypeinDirJs = strtolower($filetypeinDirJs);		        		
	        	if($filetype == "js" && $filetypeinDirJs =="js" ){				        		
	        		$sDirFull = $objInitConfif->_setLibUrlPath().$sDir.$arrTemp[$index];
	            	$sResHtml = $sResHtml.  "<script src=\" ".$sDirFull. " \" type=\"text/javascript\"></script>" . "\n";            	
	        	}	
	        	
	        	//Thuc hien include file Css
	        	$filetypeinDirCss = @substr($arrTemp[$index],strlen($file)-3,3);

        		$filetypeinDirCss = strtolower($filetypeinDirCss);	
	        	if($filetype == "css" && $filetypeinDirCss =="css"){			        		
	        		$sDirFull = $objInitConfif->_setLibUrlPath().$sDir.$arrTemp[$index];            				        		
	            	$sResHtml = $sResHtml.  "<link href=\" " .$sDirFull." \" rel=\"stylesheet\" />" . "\n";            	
	        	}	
        	}		
					
		}
		return $sResHtml;
	}
	
	/**
	 * Creater: HUNGVM
	 * Date: 05/02/2009
	 * Idea: Tao thong bao man hinh danh sach nay co bao nhieu ho so / tong so ho so; dong thoi hien thi hai radio CHON TAT CA va BO CHON TAT CA
	 *
	 * @param $psNumRowOnPage : So ban gi tren man hinh danh sach
	 * @param $psTotalRecord : Tong so ban gi
	 * @return Xau html mo ta thong tin
	 */
	public static function _selectDeselectAll($psNumRowOnPage, $psTotalRecord){
		$psHtmlString = '<table width="100%" cellpadding="0" cellspacing="0" border="0">';
		$psHtmlString .= '<tr><td height="8px"></td></tr><tr>';
		
		//Lay ra so tong so ho so tren mot trang
		if ($psNumRowOnPage > 0){
			$psHtmlString .= '<td height="20px" align="left" colspan = "2" class="small_label">';
			$psHtmlString .= '<small class="small_starmark"><font color="Red"> Danh sách này có ' . $psNumRowOnPage.'/'.$psTotalRecord. " văn bản " . '</font></small>';
			$psHtmlString .= '</td>';
			$psHtmlString .='<td class="normal_label" align="right"><font style="font-size:12px;">';
			$psHtmlString .= '<input optional = "true" type="radio" id = "rad_selectall" name="rad_selectall" value="0" onClick="select_all_checkbox(document.forms[0],\'chk_item_id\');">Chọn tất cả';
			$psHtmlString .= '<input optional = "true" type="radio" id = "rad_selectall" name="rad_selectall" value="1" onClick="deselect_all(document.forms[0],\'chk_item_id\');">Bỏ chọn tất cả';
			$psHtmlString .='</font></td>';
		}else{
			$psHtmlString .='<td height="20px" align="left" colspan = "2" class="small_label">';
			$psHtmlString .='<small class="small_starmark"><font color="Red">Danh sách này không có văn bản nào!' . '</font></small>';
			$psHtmlString .='</td>';
		}
		
		$psHtmlString .='</tr></table>';
		return $psHtmlString;
	}
	public static function _selectDeselectAllArchives($psNumRowOnPage, $psTotalRecord){
		$psHtmlString = '<table width="100%" cellpadding="0" cellspacing="0" border="0">';
		$psHtmlString .= '<tr><td height="8px"></td></tr><tr>';
		
		//Lay ra so tong so ho so tren mot trang
		if ($psNumRowOnPage > 0){
			$psHtmlString .= '<td height="20px" align="left" colspan = "2" class="small_label">';
			$psHtmlString .= '<small class="small_starmark"><font color="Red"> Danh sách này có ' . $psNumRowOnPage.'/'.$psTotalRecord. " văn bản " . '</font></small>';
			$psHtmlString .= '</td>';			
		}else{
			$psHtmlString .='<td height="20px" align="left" colspan = "2" class="small_label">';
			$psHtmlString .='<small class="small_starmark"><font color="Red">Danh sách này không có văn bản nào!' . '</font></small>';
			$psHtmlString .='</td>';
		}
		
		$psHtmlString .='</tr></table>';
		return $psHtmlString;
	}
	/*
	 * Creater: Hoang Van Toan
	 * Date: 29/09/2009
	 * Discription: Tao folder
	 *
	 * @param $path: noi can tao folder
	 * @param $folderYear: tao ra folder nam
	 * @param $folderMonth: tao ra folder thang
	 * @return tra ve duong dan toi folder
	 */
	public static function _createFolder($pathLink, $folderYear, $folderMonth, $sCurrentDay = ""){
		$sPath = '..' . str_replace("/","\\",$pathLink);
		if(!file_exists($sPath . $folderYear)){
			mkdir($sPath . $folderYear, 0777);	      
        	$sPath = $sPath . $folderYear;
            if(!file_exists($sPath . chr(92) . $folderMonth)){
        		mkdir($sPath . chr(92) . $folderMonth, 0777);
            }
		}else {
			$sPath = $sPath . $folderYear;
            if(!file_exists($sPath . chr(92) . $folderMonth)){
        		mkdir($sPath . chr(92) . $folderMonth, 0777);
        	}
		}
		//Tao ngay trong nam->thang
		if(!file_exists($sPath . chr(92) . $folderMonth . chr(92) . $sCurrentDay)){
			mkdir($sPath . chr(92) . $folderMonth . chr(92) . $sCurrentDay, 0777);
		}
		//
		$strReturn = '..' . $pathLink . $folderYear . '/' . $folderMonth . '/' . $sCurrentDay.'/';
		return $strReturn;
	}
	/**
	 * Creater: Hoang Van Toan
	 *
	 * @return Ham lay mo so ngau nhien
	 */
	function _get_randon_number(){
		$ret_value = mt_rand(1,1000000);
		return $ret_value;
	}

	/*
	 * @author :thainv
	 * @editer: Hoang Van Toan
	 * @param: '@!~!@': phan tach cac file dinh kem khac nhau
	 * @since  : 17/02/2009
	 * @see : Upload Mot mang file attach len o cung
	 * @param :
	 * @param:	$iFileMaxNum: So file toi da de upload
	 * @param :	$sDir:		  Duong dan chua file can upload 
	 * @param :	$sVarName:    Ten cua bien trong <input type="upload" name='$sVarName'>
	 * @return :
	 * 			$sFileNameList:	Mang danh sach ten file da duoc upload len o cung
	 * 
	 * @package : Efy_Publib_Library
	 * 			
	 */
	public  static function _uploadFileList($iFileMaxNum = 10, $sDir, $sVarName = "FileName", $sDelimitor = "@!~!@"){		
		$path = self::_createFolder($sDir,date('Y'),date('m'),date('d'));
		$sFileNameList = "";
		for($index = 0;$index < $iFileMaxNum; $index++){
			$random = self::_get_randon_number();
			$sAttachFileName = $sVarName . $index;
			$sFullFileName =  date("Y").'_'.date("m").'_'.date("d")."_".date("H").date("i").date("u").$random."!~!". self::_replaceBadChar($_FILES[$sAttachFileName]['name']);
			// Neu la file
			if(is_file($_FILES[$sAttachFileName]['name']) || $_FILES[$sAttachFileName]['name'] != ""){
				move_uploaded_file($_FILES[$sAttachFileName]['tmp_name'], $path . self::_convertVNtoEN($sFullFileName));
				//Neu la file
				$sFileNameList .= $sFullFileName . $sDelimitor;
			}			
		}
		// xu ly chuoi
		$sFileNameList = substr($sFileNameList,0,strlen($sFileNameList) - strlen($sDelimitor));
		// tra lai gia tri			
		return self::_convertVNtoEN($sFileNameList);			
	}
	/*
	 * Creater: Phuongtt
	 * Ham thuc hien upload anh ho so
	 * @param unknown_type $sDir
	 * @param unknown_type $sVarName
	 * @return Ambigous <tra, mixed>
	 */
	public  static function _uploadProfileImage($sDir, $sVarName = "FileName"){	
		$random = self::_get_randon_number();
		$sFullFileName =  date("Y").'_'.date("m").'_'.date("d")."_".date("H").date("i").date("u").$random."!~!". self::_replaceBadChar($_FILES[$sVarName]['name']);
		if(is_file($_FILES[$sVarName]['name']) || $_FILES[$sVarName]['name'] != ""){
			move_uploaded_file($_FILES[$sVarName]['tmp_name'], '..'.$sDir . self::_convertVNtoEN($sFullFileName));
			return self::_convertVNtoEN($sFullFileName);
		}					
		return '';
	}
	/**
	 * Creater: Hoang Van Toan
	 * date: 30/09/2009
	 *
	 * @param $strFileList: danh sach cac file dinh kem
	 * @param $deliFileList; ky tu phan tach giua cac file dinh kem
	 * @param $deliFileName: ky tu phan tach giua ID va Name cua mot file dinh kem
	 * @param $sPathLink: duong dan toi folder chua file dinh kem can hien thi
	 * @return tra ve danh sach cac file dinh kem
	 */
	public static function _getAllFileAttach($strFileList, $deliFileList = '!#~$|*', $deliFileName = '!~!', $sPathLink){
		$strFileName = explode($deliFileList,$strFileList);		
		$fileAttach = '';	
		for($i =0; $i < sizeof($strFileName); $i ++){
			$arrFileName = explode($deliFileName,$strFileName[$i]);			
			$fileName    = $arrFileName[1];
			$fileID 	 = $arrFileName[0];
			$arrFileLink = explode('_',$fileID);
			$fileLink = $sPathLink . $arrFileLink[0] . "/" . $arrFileLink[1] . "/" . $arrFileLink[2] . "/" . $strFileName[$i];
			$pathFileExist = '..' . str_replace("/","\\",$fileLink);			
			if(file_exists($pathFileExist)){												
				$fileExtensiona = explode('.', $fileName);
				$fileExtension = end($fileExtensiona);
				$fileAttach .= "<br /><a class = 'attach-file ".$fileExtension."' href = '" . self::_replaceBadChar($fileLink) ."' title = 'file dinh kem'>" . $fileName . "</a>";
			}else{
				$fileLink = $sPathLink . $arrFileLink[0] . "/" . $strFileName[$i];
				$pathFileExist = '..' . str_replace("/","\\",$fileLink);
				if(file_exists($pathFileExist)){
					$fileExtensiona = explode('.', $fileName);
					$fileExtension = end($fileExtensiona);
					$fileAttach .= "<br /><a class = 'attach-file ".$fileExtension."' href = '" . self::_replaceBadChar($fileLink) ."' title = 'file dinh kem'>" . $fileName . "</a>";
				}else{
					$fileLink = $sPathLink . $strFileName[$i];
					$pathFileExist = '..' . str_replace("/","\\",$fileLink);
					$fileExtensiona = explode('.', $fileName);
					$fileExtension = end($fileExtensiona);
					if(file_exists($pathFileExist)){
						$fileAttach .= "<br /><a class = 'attach-file ".$fileExtension."' href = '" . self::_replaceBadChar($fileLink) ."' title = 'file dinh kem'>" . $fileName . "</a>";
					}
				}
			}
		}
		return $fileAttach;
	}
	
	/*
	 * @author :thainv
	 * @since  : 19/02/2009
	 * @see : Lay tat ca cac file attach
	 * @param :
	 * 			$psID:  ID cua doi tuong can lay
	 * 			$pDocumentType: Kieu cua tai lieu can lay : PIC	
	 * 			
	 * @return :
	 * 			$arrResult:	Mang danh sach ten file da duoc upload len o cung
	 * 
	 * @package : Efy_Publib_Library
	 * 			
	 */
	public  function _getAllFileList($psID,$pDocumentType){	
		// Load Class Connection
		Zend_Loader::loadClass('Efy_Db_Connection');
		
		// Tao doi tuong
		$objConn = new Efy_DB_Connection();			
		
		$sql = "Exec Doc_GetAllDocumentFileAttach '" . $psID . "','".$pDocumentType."'" ;		
		try {						
			$arrResult = $objConn->adodbExecSqlString($sql);
		}catch (Exception $e){
			echo $e->getMessage();
		};				
		return $arrResult;		
	}	
	
	//'********************************************************************************
	//Ham _builtXmlTree
	//Muc dich: Xay dung cau truc cay du lieu (TreeView) dong khong gioi han cap do. Gom 2 loai doi tuong la:
	//	-ContainerOBJ: la dang container object chua cac object khac (Vi du: cac Phong ban, cac to chuc khac...)
	//	-LeafOBJ: la dang leaf object cuoi cung chua cac thong tin, khong chua cac object khac (Vi du: cac nhan vien...)
	//Phuong phap xay dung:
	//	-Su dung dang du lieu XML de xay dung cau truc dong tu mot mang du lieu 2 chieu.
	//	-Su dung phuong phap de quy de xay dung cau truc dong
	//Input:
	//	1. $arrAllList: Mang chua cac ban ghi cua bang can xay dung cay du lieu. Mang co cau truc sau
	//		-Phan tu thu 1 (index 0): ID cua Object
	//		-Phan tu thu 2 (index 1): ID cua Object cha chua Object ID
	//		-Phan tu thu 3 (index 2): Ma viet tat cua Object
	//		-Phan tu thu 4 (index 3): Ten cua Object
	//		-Phan tu thu 5 (index 4): Loai Object (0 - ContainerOBJ, 1 - LeafOBJ) 
	//	2. $root_text: Dong text o goc cay thu muc
	//	3. $exception_brand_id: ID cua doi tuong can hieu chinh
	//		Duoc dung trong truong hop muon hieu chinh mot doi tuong dang ConrainerOBJ
	//		Khi hieu chinh can chon lai ParentOBJ tu ModalDialog, khi do nhanh cua Object dang hieu chinh (ke ca cac ChildOBJ)
	//		se khong xuat hien tren cay thu muc (tranh loi mot Object nay vua la cha dong thoi vua la con cua Object khac)
	//		Gia tri cua ID nay: -1 neu tao tat ca cay, >0 neu tao thieu nhanh do.
	//Output:
	//	Tra ve mot chuoi dang XML cua cau truc cay du lieu
	//'********************************************************************************
	public 	static function _builtXmlTree($arrAllList,$exception_brand_id,$show_control,$opening_node_img_name,$closing_node_img_name,$leaf_node_img_name,$select_parent,$list_id_checked="",$object_name="") {
		global $_EFY_IMAGE_URL_PATH;
		global $_MODAL_DIALOG_MODE;
		
		$objConfig = new Efy_Init_Config();
		$sPath = $objConfig->_setImageUrlPath();
		
		$strTop='<?xml version="1.0" encoding="UTF-8"?>'."\n";
		$strTop.='<treeview title="Treeview" >'."\n";
		$strTop.="<custom-parameters>"."\n";
		$strTop.='<param name="shift-width" value="10"/>' . "\n";
		$strTop.='<param name="opening_node_img_name" value="'.$sPath.$opening_node_img_name.'"/>'."\n";
		$strTop.='<param name="closing_node_img_name" value="'.$sPath.$closing_node_img_name.'"/>'."\n";	
		$strTop.='<param name="leaf_node_img_name" value="'.$sPath . $leaf_node_img_name.'"/>' . "\n";
		$strTop.='<param name="modal_dialog_mode" value="'.$_MODAL_DIALOG_MODE.'"/>' . "\n";
		$strTop.='<param name="show_control" value="'.$show_control.'"/>'."\n";
		$strTop.='<param name="select_parent" value="'.$select_parent.'"/>'."\n";
		$strTop.="</custom-parameters>"."\n";	
		$strBottom= "</treeview>";
		$strXML="";
		$parent_id=NULL;
		//Lay ra mang chua cac Object muc ngoai cung 
		$v_count = sizeof($arrAllList);
		$v_current_index = 0;
		for($i=0; $i<$v_count; $i++){
			if (strcasecmp(trim($arrAllList[$i][1]),$parent_id)==0){
			//if($arrAllList[$i][1]==$parent_id){
				$arr_current_list[$v_current_index][0]=$arrAllList[$i][0];//PK
				$arr_current_list[$v_current_index][1]=$arrAllList[$i][1];//FK
				$arr_current_list[$v_current_index][2]=htmlspecialchars($arrAllList[$i][2]);//C_CODE
				$arr_current_list[$v_current_index][3]=htmlspecialchars($arrAllList[$i][3]);//C_NAME
				$arr_current_list[$v_current_index][4]=$arrAllList[$i][4];//C_TYPE
				$arr_current_list[$v_current_index][5]=$arrAllList[$i][5];//C_LEVEL
				$v_current_index++;
			}
		}
		//Tao cac Node muc 2 cua treeview
		for ($i=0; $i<$v_current_index; $i++) {
			$v_current_id = $arr_current_list[$i][0];//PK
			$v_parent_id = 0;// id cua cha (FK =0)
			$v_current_code = htmlspecialchars($arr_current_list[$i][2]);//C_CODE
			$v_current_name = htmlspecialchars($arr_current_list[$i][3]);	//C_NAME
			$v_current_type = $arr_current_list[$i][4];//C_TYPE
			$v_current_level = $arr_current_list[$i][5];//C_LEVEL
			//Kiem tra ID neu no khong la $exception_brand_id thi moi tao (tranh truong hop "vua la chau vua la cha" giua hai phan tu)
			if (strcasecmp(trim($v_current_id),$exception_brand_id)!=0){
			//if($v_current_id!=$exception_brand_id){
				$arr_id_list = explode(",",$list_id_checked);
				$value_checked = 0;
				for ($j=0;$j<sizeof($arr_id_list);$j++){
					if ($arr_id_list[$j]==$v_current_id){
						$value_checked = $v_current_id;
					}				
				}
				$strXML.= '<folder title="'.trim($v_current_name).'" id="'.$v_current_id.'" value="'.$v_current_code.'" value_check="'.$value_checked.'" type="'.$v_current_type.'" parent_id="'.$v_parent_id.'" xml_tag_in_db_name="'.$object_name.'" level="'.$v_current_level.'" >'."\n";
				//Tao ra cac Node  con cua tree view
				$strXML.= self::_builtChildNode($arrAllList,$v_current_level,$v_current_id,$exception_brand_id,$list_id_checked,$object_name);
				$strXML.="</folder>"."\n";
			}
		}
		return  $strTop . $strXML . $strBottom;
	
	}
		
	
/**
	 * ******************************************************************************************************************
	 * @Idea: tra ve mot gia tri cua mot thuoc tinh cua mot phan tu mang.
	 * @param $p_array : Mang danh sach cac phan tu
	 * @param $p_id : Id cua phan tu can lay trong mang $p_array
	 * @param $p_attr_name : Ten phan tu can lay
	 * @return  Ten phan tu can lay
	 *******************************************************************************************************************
	 */		
	public static function _getItemAttrById($p_array,$p_id,$p_attr_name) {		
		try {
			foreach($p_array as $staff){
				if ($staff['id'] == $p_id){					
					return $staff[$p_attr_name];
					break;
				}
			}
			return "";
		}catch (Exception $ex){;}
	}
	/**
	 * Creater: Hoang Van Toan
	 * Date: 30/10/2009
	 * Dis: lay Name boi Code trong danh muc
	 *
	 * @param  $p_array
	 * @param  $p_id
	 * @param  $p_attr_name
	 * @return Ten cua doi tuong duoc truyen vao
	 */
	public static function _getNameByCode($p_array,$p_id,$p_attr_name) {		
		try {
			foreach($p_array as $staff){
				if ($staff['C_CODE'] == $p_id){					
					return $staff[$p_attr_name];
					break;
				}
			}
			return "";
		}catch (Exception $ex){;}
	}	
	//Lay danh sach tat ca cac phogn ban
	public static function _getArrAllUnit(){
		try {
			$i = 0;
			foreach($_SESSION['arr_all_unit'] as $v_unit){
				$arr_child_unit[$i][0] = $v_unit['id'];
				$arr_child_unit[$i][1] = $v_unit['parent_id'];
				$arr_child_unit[$i][2] = $v_unit['code'];
				$arr_child_unit[$i][3] = $v_unit['name'];
				$arr_child_unit[$i][4] = 0;
				$arr_child_unit[$i][5] = 0;
				$i++;
			}
			return $arr_child_unit;	
		}catch (Exception $ex){;}
	}
	
	//*********************************************************************************************************************
	//Lay danh sach nguoi su dung cua mot don vi
	//*********************************************************************************************************************
	public static function _getArrChildStaff($arr_unit){
		try {
			$i = 0;
			$v_count = sizeof($arr_unit);
			for($j=0; $j < $v_count; $j++){
				foreach($_SESSION['arr_all_staff'] as $v_staff){
					if($v_staff['unit_id'] == $arr_unit[$j]['0']){
						$arr_child_staff[$i][0] = $v_staff['id'];
						$arr_child_staff[$i][1] = $v_staff['unit_id'];
						if (isset($v_staff['code'])){
							$arr_child_staff[$i][2] = $v_staff['code'];
						}	
						$arr_child_staff[$i][3] = $v_staff['name'];
						$arr_child_staff[$i][4] = 1;
						$arr_child_staff[$i][5] = 1;
						$i++;
					}
				}
			}
			return $arr_child_staff;
		}catch (Exception $ex){;}
	}
	
	//********************************************************************************************************************
	//Thuc hien noi array2 vao array1 voi so phan tu cua 2 mang la $number_element
	//********************************************************************************************************************
	public static function _attachTwoArray($p_array1, $p_array2, $number_element){
		$v_count_arr1 = sizeof($p_array1);
		$v_count_arr2 = sizeof($p_array2);		
		$j = $v_count_arr1;		
		for($i = 0; $i<$v_count_arr2; $i++){
			for($h=0; $h<=$number_element; $h++){
				if (isset($p_array2[$i][$h])){
					$p_array1[$j][$h] = $p_array2[$i][$h];
				}else{
					$p_array1[$j][$h] = null;
				}					
			}
			$j++;
		}				
		return $p_array1;
	}
	
	/*
	 * Enter description here...
	 *
	 * @param unknown_type $arrAllList
	 * @param unknown_type $current_level
	 * @param unknown_type $parent_id
	 * @param unknown_type $exception_brand_id
	 * @param unknown_type $list_id_checked
	 * @param unknown_type $object_name
	 * @return unknown
	 */
	//Xay dung cac node con cua mot doi tuong
	public static function _builtChildNode($arrAllList,$current_level,$parent_id,$exception_brand_id,$list_id_checked="",$object_name=""){
		$strXML="";
		$v_current_index = 0;
		$v_count = sizeof($arrAllList);
		for($j=0;$j<$v_count;$j++){
		//Tim nhung thang con
			if ((strcasecmp(trim($arrAllList[$j][1]),$parent_id)==0) && ($arrAllList[$j][5]>=$current_level)){
			//if (($arrAllList[$j][1]==$parent_id) and ($arrAllList[$j][5]>=$current_level)){
				$arr_current_list[$v_current_index][0]=$arrAllList[$j][0];//PK
				$arr_current_list[$v_current_index][1]=$arrAllList[$j][1];//FK
				$arr_current_list[$v_current_index][2]=htmlspecialchars($arrAllList[$j][2]);//C_CODE
				$arr_current_list[$v_current_index][3]=htmlspecialchars($arrAllList[$j][3]);//C_NAME			
				$arr_current_list[$v_current_index][4]=$arrAllList[$j][4];//C_TYPE
				$arr_current_list[$v_current_index][5]=$arrAllList[$j][5];//C_LEVEL
				$v_current_index++;
			}
		}
		//Truong hop mang $arr_current_list rong thi ket thuc de quy
		if($v_current_index <= 0){return;}
		for ($i=0; $i<$v_current_index; $i++){
			$v_current_id = $arr_current_list[$i][0];//PK
			$v_parent_id = $arr_current_list[$i][1];//FK	
			$v_current_code = htmlspecialchars($arr_current_list[$i][2]);//C_CODE
			$v_current_name = htmlspecialchars($arr_current_list[$i][3]);//C_NAME
			$v_current_type = $arr_current_list[$i][4];//C_TYPE
			$v_current_level = $arr_current_list[$i][5];//C_LEVEL
			//Kiem tra ID neu no khong la $exception_brand_id thi moi tao
			if (strcasecmp(trim($v_current_id),$exception_brand_id)!=0){
			//if($v_current_id!=$exception_brand_id){
				$arr_id_list = explode(",",$list_id_checked);
				$value_checked = 0;
				for ($j=0;$j<sizeof($arr_id_list);$j++){
					if ($arr_id_list[$j]==$v_current_id){
						$value_checked = $v_current_id;
					}				
				}
				$strXML.= '<folder title="'.trim($v_current_name).'" id="'.$v_current_id.'" value="'.$v_current_code.'" value_check="'.$value_checked.'" type="'.$v_current_type.'" parent_id="'.$parent_id.'" xml_tag_in_db_name="'.$object_name.'" level="'.$v_current_level.'" >'."\n";
				if ($v_current_type=='0'){
					$strXML.=self::_builtChildNode($arrAllList,$v_current_level,$v_current_id,$exception_brand_id,$list_id_checked,$object_name);
				}
				$strXML.="</folder>"."\n";
			}
		}
		return  $strXML;
	}
	
	/*
	 * Creater : HUNGVM
	 * Date : 21/05/2009
	 * Idea : Tao phuong thuc be dong tren ma hinh danh sach (Vi du: Nhap noi dung trong textarea co xuong dong tuy nhien khi hien thi ra man hinh danh sach thi
	 * thi lai hien thi tren mot dong)
	 *
	 * @param $pContent : Noi dung can be dong
	 * @return Xau noi dung da duoc be
	 */
	public static function _breakLine ($pContent = ''){
		$ilen = strlen($pContent);
		if($ilen > 0){			
			for($index = 0; $index < $ilen; $index++){
				if(ord(substr($pContent,$index,1)) == 10){//=10 la ma xuong dau dong
					$pContent = str_replace(chr(10),"<br>",$pContent);
				}
			}	
		}
		return $pContent;
	}	
	//*************************************************************************
	//Muc dich:Kiem tra xem trong danh sach $p_list co chua mot gia tri $p_element hay khong	
	//*************************************************************************
	
	/*
	 * Creater : HUNGVM
	 * Date : 21/06/2009
	 * Idea : Phuong thuc kiem tra co ton tai mot phan tu trong tap gia tri khong? (true => ton tai; false => khong ton tai)
	 *
	 * @param $p_list	: Tap phan tu
	 * @param $p_element : Phan tu can kiem tra
	 * @param $p_delimitor : Ky tu phan tach giua cac phan tu trong $p_list
	 * @return Tra lai gia tri true/false
	 */
	public static function _listHaveElement($p_list, $p_element, $p_delimitor){
		if ($p_list=="" Or $p_element==""){
			return false;
		}
		$ret_value = false;
		if(strlen($p_list)>0){
			$array = explode($p_delimitor, $p_list);
			$ret_value = in_array($p_element,$array);
		}
		return $ret_value;
	}
	public static function _InforStaff(){
		$StaffName = Efy_Publib_Library::_getItemAttrById($_SESSION['arr_all_staff'],$_SESSION['staff_id'],'name');
		$piUnitId = Efy_Publib_Library :: _getItemAttrById($_SESSION['arr_all_staff'],$_SESSION['staff_id'],'unit_id');
		$piUnitName = Efy_Publib_Library::_getItemAttrById($_SESSION['arr_all_unit'],$piUnitId,'name');			
		return $StaffName."<br>".$piUnitName;
	}	

	
	 	
	/*
	 * Creater : HUNGVM
	 * Date : 30/09/2009
	 * Idea : Tao phuong thuc hien thi thong tin nguoi dang nhap hien thoi
	 *
	 * @return Chuoi HTML hien thi thong tin nguoi dang nhap
	 */
	public static function _getInformationStaffLoginMtl($sStaffName = "",$sPositionName = "", $sUnitName = "",$baseUrl =""){	
		$strHtml = "";
		if ($sStaffName != ""){
			$strHtml = '<p class="information_acc">'. $sPositionName . ' - ' . $sStaffName . '</p>';
			$strHtml .= '<p class="information_acc">'. $sUnitName . '</p>';
			$strHtml .= '<p class="information_singup" id="changepass"> '. $sUnitName . '</p>';
			$urlRe = $baseUrl . "../logout/index";
			// $strHtml .= '<p class="information_singup"><span onclick="reloadurl(\''.$urlRe.'\')" style="cursor:pointer;">Thoát<span></p>';
			$strHtml .= '<p class="information_singup" onclick="reloadurl(\''.$urlRe.'\')" style="cursor:pointer;">Thoát</p>';
		}	
		return $strHtml;
	}
	/*
	 * Creater: hoang van toan
	 * date(29/10/2009)
	 * Dics: ham chuyen ky tu chu thuong thanh chu HOA
	 *
	 * @param $strText: chuoi ky tu truyen vao
	 */
	public static function Lower2Upper($strText){
		$strLC = "a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|á|à|ả|ã|ạ|ă|ắ|ặ|ằ|ẳ|ẵ|â|ấ|ầ|ẩ|ẫ|ậ|đ|é|è|ẻ|ẽ|ẹ|ê|ế|ề|ể|ễ|ệ|í|ì|ỉ|ĩ|ị|ó|ò|ỏ|õ|ọ|ô|ố|ồ|ổ|ỗ|ộ|ơ|ớ|ờ|ở|ỡ|ợ|ú|ù|ủ|ũ|ụ|ư|ứ|ừ|ử|ữ|ự|ý|ỳ|ỷ|ỹ|ỵ'";
		$strUC = "A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|Á|À|Ả|Ã|Ạ|Ă|Ắ|Ặ|Ằ|Ẳ|Ẵ|Â|Ấ|Ầ|Ẩ|Ẫ|Ậ|Đ|É|È|Ẻ|Ẽ|Ẹ|Ê|Ế|Ề|Ể|Ễ|Ệ|Í|Ì|Ỉ|Ĩ|Ị|Ó|Ò|Ỏ|Õ|Ọ|Ô|Ố|Ồ|Ổ|Ỗ|Ộ|Ơ|Ớ|Ờ|Ở|Ỡ|Ợ|Ú|Ù|Ủ|Ũ|Ụ|Ư|Ứ|Ừ|Ử|Ữ|Ự|Ý|Ỳ|Ỷ|Ỹ|Ỵ'";
		//$strLC = "a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|Ã¡|Ã |áº£|Ã£|áº¡|Äƒ|áº¯|áº·|áº±|áº³|áºµ|Ã¢|áº¥|áº§|áº©|áº«|áº­|Ä‘|Ã©|Ã¨|áº»|áº½|áº¹|Ãª|áº¿|á»|á»ƒ|á»…|á»‡|Ã­|Ã¬|á»‰|Ä©|á»‹|Ã³|Ã²|á»|Ãµ|á»|Ã´|á»‘|á»“|á»•|á»—|á»™|Æ¡|á»›|á»|á»Ÿ|á»¡|á»£|Ãº|Ã¹|á»§|Å©|á»¥|Æ°|á»©|á»«|á»­|á»¯|á»±|Ã½|á»³|á»·|á»¹|á»µ'";
		//$strUC = "A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|Ã|Ã€|áº¢|Ãƒ|áº |Ä‚|áº®|áº¶|áº°|áº²|áº´|Ã‚|áº¤|áº¦|áº¨|áºª|áº¬|Ä|Ã‰|Ãˆ|áºº|áº¼|áº¸|ÃŠ|áº¾|á»€|á»‚|á»„|á»†|Ã|ÃŒ|á»ˆ|Ä¨|á»Š|Ã“|Ã’|á»Ž|Ã•|á»Œ|Ã”|á»|á»’|á»”|á»–|á»˜|Æ |á»š|á»œ|á»ž|á» |á»¢|Ãš|Ã™|á»¦|Å¨|á»¤|Æ¯|á»¨|á»ª|á»¬|á»®|á»°|Ã|á»²|á»¶|á»¸|á»´'";
		$arrLC = explode('|', $strLC);
		$arrUC = explode('|', $strUC);
		for($i =0; $i <sizeof($arrLC); $i ++){
			$strText = str_replace($arrLC[$i], $arrUC[$i], $strText);
		}	
		return 	$strText; 
	}
	public static function _deleteFileUpload($url){
		return unlink($url);
	}
	
	/*
        Chuc nang:	Sinh ra cac tuan trong mot nam
		Tham so:
		+	$p_year (int): Xac dinh nam. Vidu: $p_year=2004
		+	$p_number_of_week (int) So tuan se duoc hien thi trong combo_box:
				= -1 : hien thi tat ca cac tuan trong nam
				=  0 : Hien thi tu tuan dau toi tuan hien thoi
				n >0 : Hien thi n tuan tinh tu tuan hien thoi (neu muon hien thi tu tuan hien thoi den het nam thi n>=53)
		+	$p_current_week (int): Tuan hien thoi hien dang duoc chon trong combo_box. Vi du: $p_current_week=33
	 */
	public static function _generateWeeksOfYear($p_year, $p_number_of_week, $p_current_week){
		$p_week_name = "Tu&#7847;n ";
		//Xac dinh ngay 1/1 la thu may
		$v_timestamp = mktime(0,0,0,1,1,$p_year);
		$v_fisrt_day_of_year = date('w',$v_timestamp);
		if ($v_fisrt_day_of_year == 0) {$v_fisrt_day_of_year = 7;}
		//Xac dinh ngay dau cua tuan thu nhat la ngay nao, ngay nay co the thuoc nam truoc.
		if ($v_fisrt_day_of_year <= 4){
			$v_day = 2 - $v_fisrt_day_of_year;
		}else{
			$v_day = 9 - $v_fisrt_day_of_year;
		}
		$strHTML = "";
		for ($i=1; $i <= 53; $i++){
			$v_fisrt_day_of_week = date("d/m/Y",mktime(0,0,0,1,$v_day,$p_year));
			$v_last_day_of_week = date("d/m/Y",mktime(0,0,0,1,$v_day+6,$p_year));
			$v_text = $p_week_name.$i.' ('.$v_fisrt_day_of_week.' --> '.$v_last_day_of_week.')';
			if($i == $p_current_week){
				$str_selected = "selected";
			}else{
				$str_selected = "";
			} 
			// Hien thi toan bo (ngam dinh)
			$add_HTML=true;
			if ($p_number_of_week == 0){ // Hien thi tu tuan 1 toi tuan hien thoi
				if ($i > date("W")){break;}
			}
			if ($p_number_of_week > 0){ // Hien thi n tuan tu tuan hien thoi tro di
				if ($i < date("W")){
					$add_HTML=false;
				}else{
					$add_HTML=true;
					if ($i - date("W") >= $p_number_of_week){break;}
				}
			}
			if ($add_HTML == true){
				$strHTML.='<option id='.'"'.$i.'"'.' name='.'"'.$i.'"';
				$strHTML.=' value='.'"'.$i.'"';
				$strHTML.=' fisrt_day='.'"'.$v_fisrt_day_of_week.'"';
				$strHTML.=' last_day='.'"'.$v_last_day_of_week.'"';
				$strHTML.=' '.$str_selected.'>' .$v_text.'</option>';
			}
			$v_day = $v_day + 7;
			//Kiem tra tuan sau da sang tuan thu nhat cua nam sau chua.
			if (date("W",mktime(0,0,0,1,$v_day,$p_year)) == 1){break;}
		}
		return $strHTML;
	}
    /*
	 * Creater: Phongtd
	 * Date: 12/05/2010
	 * IDea: Tao mot xau HTML mo ta danh sach cac trang (Trang 1; Trang 2;...)
	 *
	 * @param $piTotalRecord : Tong so trang
	 * @param $piCurrentPage : Trang hien thoi
	 * @param $piNumberRecordOnList : So ban ghi / trang
	 * @param $pAction : Thuc hien Action
	 * @return Xau html
	 */
	public static function _generateStringNumberPage($piTotalRecord, $piCurrentPage, $piNumberRecordOnList,$pUrl){
		if($piTotalRecord > $piNumberRecordOnList){
			//Xau hien thi danh sach trang
			$psHtmlString = "";
			//Trang bat dau hien thi
			$piStartPage = 1;
			//Trang ket thuc hien thi
			$piEndPage = 10;
			//Tinh tong so trang
			if ($piTotalRecord % $piNumberRecordOnList == 0){
				$psNumberPage = (int)($piTotalRecord / $piNumberRecordOnList);
			}else{
				$psNumberPage = (int)($piTotalRecord / $piNumberRecordOnList)+1;		
			}
			$psHtmlString = $psHtmlString . "<tr align='center'>";
			if($piCurrentPage >1){
				$piCurrentPagepre =$piCurrentPage - 1;
				$psHtmlString = $psHtmlString . "<td width='2%' onclick = 'break_page(\"$piCurrentPagepre\",\"$pUrl\");'>"."<a><b><u>Trước</u></b></a>"."</td>";
			}
			//Truong hop tong so trang nho hon so trang can hien thi
			if($psNumberPage <= $piEndPage){ 
				for ($index = 1; $index <= $psNumberPage; $index++){
					$iCurren = $index;
					if($index == $piCurrentPage){
						$iCurren = "<b>" . $index . "</b>";
					}
					$psHtmlString = $psHtmlString . "<td width='1%' onclick='break_page(\"$index\",\"$pUrl\"); '>"."<a><span>".$iCurren."</span></a>". "</td>";		
				}
			//Truong hop tong so trang lon hon so trang can hien thi	
			}else {
				if($piCurrentPage >6){
					//Hien thi truoc va sau trang hien tai 5 trang
					$piStartPage = $piCurrentPage - 5;
					$index = $piStartPage;
					//Neu chi so trang dau tien cong trang cuoi cung nho hon tong so trang
					if($piStartPage + $piEndPage < $psNumberPage){
						for ($index; $index <= $piStartPage + $piEndPage; $index++){
							$iCurren = $index;
							if($index == $piCurrentPage){
								$iCurren = "<b>" . $index . "</b>";
							}						
							$psHtmlString = $psHtmlString . "<td width='1%' onclick='break_page(\"$index\",\"$pUrl\"); '>"."<a><span>".$iCurren."</span></a>". "</td>";				
						}
					//Neu chi so trang dau tien cong trang cuoi cung lon hon tong so trang	
					}else{
						$index = $psNumberPage - $piEndPage;
						for ($index; $index <= $psNumberPage; $index++){
							$iCurren = $index;
							if($index == $piCurrentPage){
								$iCurren = "<b>" . $index . "</b>";
							}
							$psHtmlString = $psHtmlString . "<td width='1%' onclick='break_page(\"$index\",\"$pUrl\"); '>"."<a><span>".$iCurren."</span></a>". "</td>";			
						}
					}
				}else{
					for ($index=$piStartPage; $index <=$piEndPage; $index++){	
						$iCurren = $index;
						if($index == $piCurrentPage){
							$iCurren = "<b>" . $index . "</b>";
						}
						$psHtmlString = $psHtmlString . "<td width='1%' onclick='break_page(\"$index\",\"$pUrl\"); '>"."<a><span>".$iCurren."</span></a>". "</td>";					
					}
				}
			}
			if($piCurrentPage < $psNumberPage){
				$piCurrentPagenex = $piCurrentPage +1;
				$psHtmlString = $psHtmlString . "<td width='2%' onclick = 'break_page(\"$piCurrentPagenex\",\"$pUrl\");'>"."<a><b><u>Tiếp</u></b></a>" ."</td>";
			}
			$psHtmlString = $psHtmlString . "</tr>";		
			return $psHtmlString;
		}	
	}
	/*
	 * Creater: Nghiat
	 * Date: 07/06/2010
	 * IDea: Lay mot ngay bat ky trong tuan cua nam(Trang 1; Trang 2;...)
	 *
	 * @param $year(int) : Xac dinh nam
	 * @param $numberOfWeek(int) : Tuan thu may trong nam
	 * @param $orderDate : Lay ngay thu may trong tuan
	 * @return Ngay trong tuan
	 */
	public	static function _getAnyDateOnWeekOfYear($year, $numberOfWeek, $orderDate){
		//Xac dinh ngay 1/1 la thu may
		$timestamp = mktime(0,0,0,1,1,$year);
		$fisrtDayOfYear = date('w',$timestamp);
		if ($fisrtDayOfYear == 0) {$fisrtDayOfYear = 7;}
		//Xac dinh ngay dau cua tuan thu nhat la ngay nao, ngay nay co the thuoc nam truoc.
		if ($fisrtDayOfYear <= 4){
		$day = 2 - $fisrtDayOfYear;
		}else{
		$day = 9 - $fisrtDayOfYear;
		}
		for ($i=1; $i <= 53; $i++){
		if($i == $numberOfWeek){
		$dateOfWeek = date("d/m/Y",mktime(0,0,0,1,$day+$orderDate,$year));
		break;
		}
		$day = $day + 7;
		//Kiem tra tuan sau da sang tuan thu nhat cua nam sau chua.
		if (date("W",mktime(0,0,0,1,$day,$year)) == 1){break;}
		}
		return $dateOfWeek;
	}
	/*
	 * Creater: Phuongtt
	 * Date: 16/05/2010
	 * Dis: lay CODE boi Name trong danh muc
	 *
	 * @param  $p_array
	 * @param  $p_attr_name
	 * @param  $p_id
	 * @return Ten cua doi tuong duoc truyen vao
	 */
	public static function _getCodeByName($p_array,$p_attr_name,$p_id) {		
		try {
			foreach($p_array as $staff){
				if ($staff['C_NAME'] == $p_attr_name){					
					return $staff[$p_id];
					break;
				}
			}
			return "";
		}catch (Exception $ex){;}
	}	
	/*
	 * Creater: Phuongtt
	 *
	 * @param $strText: chuoi ky tu can chuyen font tu VN sang EN
	 * @return tra ve chuoi khong dau
	 */
    function _convertVNtoEN($strText){
    	$vnChars = array("á","à","ả","ã","ạ","ă","ắ","ằ","ẳ","ẵ","ặ","â","ấ","ầ","ẩ","ẫ","ậ","é","è","ẻ","ẽ","ẹ","ê","ế","ề","ể","ễ","ệ","í","ì","ì","ỉ","ĩ","ị","ó","ò","ỏ","õ","ọ","ô","ố","ồ","ổ","ỗ","ộ","ơ","ớ","ờ","ở","ỡ","ợ","ú","ù","ủ","ũ","ụ","ư","ứ","ừ","ử","ữ","ự","ý","ỳ","ỷ","ỹ","ỵ","đ","Á","﻿À","Ả","Ã","Ạ","Ă","Ắ","Ằ","Ẳ","Ẵ","Ặ","Â","Ấ","Ầ","Ẩ","Ẫ","Ậ","É","È","Ẻ","Ẽ","Ẹ","Ê","Ế","Ề","Ể","Ễ","Ệ","Í","Ì","Ỉ","Ĩ","Ị","Ó","Ò","Ỏ","Õ","Ọ","Ô","Ố","Ồ","Ổ","Ỗ","Ộ","Ơ","Ớ","Ờ","Ở","Ỡ","Ợ","Ú","Ù","Ủ","Ũ","Ụ","Ư","Ứ","Ừ","Ử","Ữ","Ự","Ý","Ỳ","Ỷ","Ỹ","Ỵ","Đ");
    	$enChars = array("a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","e","e","e","e","e","e","e","e","e","e","e","i","i","i","i","i","i","o","o","o","o","o","o","o","o","o","o","o","o","o","o","o","o","o","u","u","u","u","u","u","u","u","u","u","u","y","y","y","y","y","d","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","E","E","E","E","E","E","E","E","E","E","E","I","I","I","I","I","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","O","U","U","U","U","U","U","U","U","U","U","U","Y","Y","Y","Y","Y","D");
    	for($i =0; $i <sizeof($vnChars); $i ++){
			$strText = str_replace($vnChars[$i], $enChars[$i], $strText);
		}	
		return 	$strText; 
    }
    /*
     *Creater: HUNGVM
     *create date: 19/10/2008
     *Idea: Generate list empty row
     * @param  string $pCurrentRow => number current row
     * @param  string $pTotalRow => number total row
     * @param  string $pCurrentStyleName class name
     * @param  string $pNextStyleName class name
     * @param  string $pTotalColumn number colums
     * @return $strHTML
     */
    public static function _addEmptyRow($pCurrentRow,$pTotalRow,$pCurrentStyleName,$pTotalColumn) {    			
		//Dinh dang style
		if ($pCurrentStyleName == "odd_row"){
			$pNextStyleName = "round_row";
		}else{
			$pNextStyleName = "odd_row";
		}    		
		
		if($pCurrentRow>=$pTotalRow) {
			return "";
		}
		$strHTML = "";
		$style_name = $pCurrentStyleName;
		for($ii=$pCurrentRow+1;$ii<=$pTotalRow;$ii++) {
			if($style_name == $pCurrentStyleName) { 
				$style_name = $pNextStyleName;
			} else {
				$style_name = $pCurrentStyleName;
			}
			$strHTML.='<tr class='.'"'."$style_name".'"'.'>';
			for($jj=1;$jj<=$pTotalColumn;$jj++) {		
				$strHTML.="<td>&nbsp;</td>";
			}
			$strHTML.="</tr>";
		}
		return $strHTML;
	}
	/*
     *Creater: HUNGVM
     *create date: 19/10/2008
     *Idea: Generate header of table
     *parameter:
     * 		@param  array $widthCols => height of cols
     *	 	@param  array $TitleCols => title of cols
     * 		@param  string $delimitor special char
     * 		@return $strHTML
     * 
     * 
     * Editer: TOANHV
     * Edit date: 17/09/2009
     */
     public static function _GenerateHeaderTable($widthCols,$TitleCols,$delimitor) {       	
    	//Xu ly sinh cac cot ung voi do rong tuong ung cua Table    	
    	$arrWidthCol = explode($delimitor,$widthCols);//Mang luu thong tin do rong cac cot
    	$arrTitleCol = explode($delimitor,$TitleCols);//Mang luu thong tin luu ten tot tuong ung    	
    	$countCol = sizeof($arrWidthCol);
    	$countTitle = sizeof($arrTitleCol);
    	//Tao col
    	$strHTML = "";    	    	
    	for($index = 0; $index < $countCol; $index++){
    		$strHTML = $strHTML . "<col width='" . $arrWidthCol[$index] . "'>";
    	}
    	$psHtmlTempWidth = $strHTML;
    	$strHTML = $strHTML . "<tr class='header'>"; 	
    	for($index = 0; $index < $countCol; $index++){
			$styleCol = "";
			$strHTML = $strHTML . "<td class = 'title' style = 'text-align:center;'>" . $arrTitleCol[$index] . "</td>";
    	}  
    	$strHTML = $strHTML . "</tr>";
    	return $strHTML . "!~~!". $psHtmlTempWidth;
	
	}

	/*
	 * Creater: Toanhv
	 * Date: 04/01/2011
	 * Dis: chuyển đổi kiểu số nguyên về kiểu tiền tệ
	 *
	 * @param $sValue: giá trị cần chuyển đổi
	 * @param $dili: ký tự phân tách
	 */
	public static function _convertToMoney($sValue, $dili = ','){
		$sValue = trim($sValue);
		if ($sValue == 0) return '';
		$count = strlen((string)$sValue);
		$begin = 0;
		if($sValue*1 < 0)
			$begin = 1;
		if($count > 3){
			$k = -1;
			$strValue = "";
			for($i = $count -1; $i >=$begin; $i --){
				$k ++;
				if($k % 3 == 0 && $k > 0){
					$strValue = $strValue . $dili;
				}
				$strValue = $strValue . $sValue[$i];
			}		
			if($begin == 1)	
				return '-' . strrev($strValue);
			else
				return strrev($strValue);
		}
		return $sValue;
	}
	/*
	 * Phuongtt
	 * ham doc so tien
	 * @param unknown_type $amount
	 */
	function _BsVndText($amount)
	{
        $Text=array("không", "một", "hai", "ba", "bốn", "năm", "sáu", "bảy", "tám", "chín");
        $TextLuythua =array("","nghìn", "triệu", "tỷ", "ngàn tỷ", "triệu tỷ", "tỷ tỷ");
        $textnumber = "";
        $length = strlen($amount);
       
        for ($i = 0; $i < $length; $i++)
        $unread[$i] = 0;
       
        for ($i = 0; $i < $length; $i++)
        {              
            $so = substr($amount, $length - $i -1 , 1);               
           
            if ( ($so == 0) && ($i % 3 == 0) && ($unread[$i] == 0)){
                for ($j = $i+1 ; $j < $length ; $j ++)
                {
                    $so1 = substr($amount,$length - $j -1, 1);
                    if ($so1 != 0)
                        break;
                }                      
                      
                if (intval(($j - $i )/3) > 0){
                    for ($k = $i ; $k <intval(($j-$i)/3)*3 + $i; $k++)
                        $unread[$k] =1;
                }
            }
        }
       
        for ($i = 0; $i < $length; $i++)
        {       
            $so = substr($amount,$length - $i -1, 1);      
            if ($unread[$i] ==1)
            continue;
           
            if ( ($i% 3 == 0) && ($i > 0))
            $textnumber = $Text[$so] . ' ' . $TextLuythua[$i/3] ." ". $textnumber;    
           
            if ($i % 3 == 2 )
            $textnumber = $Text[$so] . ' ' . 'trăm ' . $textnumber;
           
            if ($i % 3 == 1)
            $textnumber = $Text[$so] . ' ' . 'mươi ' . $textnumber;
        }
        $textnumber = str_replace("không mươi", "lẻ", $textnumber);
        $textnumber = str_replace("lẻ không", "", $textnumber);
        $textnumber = str_replace("mươi không", "mươi", $textnumber);
        $textnumber = str_replace("một mươi", "mười", $textnumber);
        $textnumber = str_replace("mươi năm", "mươi lăm", $textnumber);
        $textnumber = str_replace("mươi một", "mươi mốt", $textnumber);
        $textnumber = str_replace("mười năm", "mười lăm", $textnumber);
        return ucfirst($textnumber." đồng chẵn");
	}
	/*
	 * Creater: Nghiat
	 *	24/01/2011
	 * @param $sText: Chuyen doi chuoi tu TCVN3 sang Unicode
	 * @return tra ve font Unicode
	 */
    function _convertTCVN3ToUnicode($inputText){
    	$uniChars = array("á","à","ả","ã","ạ","ă","ắ","ằ","ẳ","ẵ","ặ","â","ấ","ầ","ẩ","ẫ","ậ","é","è","ẻ","ẽ","ẹ","ê","ế","ề","ể","ễ","ệ","í","ì","ỉ","ĩ","ị","ó","ò","ỏ","õ","ọ","ô","ố","ồ","ổ","ỗ","ộ","ơ","ớ","ờ","ở","ỡ","ợ","ú","ù","ủ","ũ","ụ","ư","ứ","ừ","ử","ữ","ự","ý","ỳ","ỷ","ỹ","ỵ","đ","Á","﻿À","Ả","Ã","Ạ","Ă","Ắ","Ằ","Ẳ","Ẵ","Ặ","Â","Ấ","Ầ","Ẩ","Ẫ","Ậ","É","È","Ẻ","Ẽ","Ẹ","Ê","Ế","Ề","Ể","Ễ","Ệ","Í","Ì","Ỉ","Ĩ","Ị","Ó","Ò","Ỏ","Õ","Ọ","Ô","Ố","Ồ","Ổ","Ỗ","Ộ","Ơ","Ớ","Ờ","Ở","Ỡ","Ợ","Ú","Ù","Ủ","Ũ","Ụ","Ư","Ứ","Ừ","Ử","Ữ","Ự","Ý","Ỳ","Ỷ","Ỹ","Ỵ","Đ");
    	$tcvnChars = array("¸","µ","¶","·","¹","¨","¾","»","¼","½","Æ","©","Ê","Ç","È","É","Ë","Ð","Ì","Î","Ï","Ñ","ª","Õ","Ò","Ó","Ô","Ö","Ý","×","Ø","Ü","Þ","ã","ß","á","â","ä","«","è","å","æ","ç","é","¬","í","ê","ë","ì","î","ó","ï","ñ","ò","ô","­","ø","õ","ö","÷","ù","ý","ú","û","ü","þ","®","¸","#µ","¶","·","¹","¡","¾","»","¼","½","Æ","¢","Ê","Ç","È","É","Ë","Ð","Ì","Î","Ï","Ñ","£","Õ","Ò","Ó","Ô","Ö","Ý","×","Ø","Ü","Þ","ã","ß","á","â","ä","¤","è","å","æ","ç","é","¥","í","ê","ë","ì","î","ó","ï","ñ","ò","ô","¦","ø","õ","ö","÷","ù","ý","ú","û","ü","þ","§");
    	for($i =0; $i <sizeof($tcvnChars); $i ++){
			$outputText = str_replace($tcvnChars[$i], $uniChars[$i], $inputText);
		}	
		return 	$outputText; 
    }
    /*
	 * Creater: Nghiat
	 *	24/01/2011
	 * @param $sText: Chuyen doi chuoi tu Unicode  sang TCVN3
	 * @return tra ve font TCVN3
	 */
    function _convertUnicodeToTCVN3($inputText){
    	$uniChars = array("á","à","ả","ã","ạ","ă","ắ","ằ","ẳ","ẵ","ặ","â","ấ","ầ","ẩ","ẫ","ậ","é","è","ẻ","ẽ","ẹ","ê","ế","ề","ể","ễ","ệ","í","ì","ỉ","ĩ","ị","ó","ò","ỏ","õ","ọ","ô","ố","ồ","ổ","ỗ","ộ","ơ","ớ","ờ","ở","ỡ","ợ","ú","ù","ủ","ũ","ụ","ư","ứ","ừ","ử","ữ","ự","ý","ỳ","ỷ","ỹ","ỵ","đ","Á","﻿À","Ả","Ã","Ạ","Ă","Ắ","Ằ","Ẳ","Ẵ","Ặ","Â","Ấ","Ầ","Ẩ","Ẫ","Ậ","É","È","Ẻ","Ẽ","Ẹ","Ê","Ế","Ề","Ể","Ễ","Ệ","Í","Ì","Ỉ","Ĩ","Ị","Ó","Ò","Ỏ","Õ","Ọ","Ô","Ố","Ồ","Ổ","Ỗ","Ộ","Ơ","Ớ","Ờ","Ở","Ỡ","Ợ","Ú","Ù","Ủ","Ũ","Ụ","Ư","Ứ","Ừ","Ử","Ữ","Ự","Ý","Ỳ","Ỷ","Ỹ","Ỵ","Đ");
    	$tcvnChars = array("¸","µ","¶","·","¹","¨","¾","»","¼","½","Æ","©","Ê","Ç","È","É","Ë","Ð","Ì","Î","Ï","Ñ","ª","Õ","Ò","Ó","Ô","Ö","Ý","×","Ø","Ü","Þ","ã","ß","á","â","ä","«","è","å","æ","ç","é","¬","í","ê","ë","ì","î","ó","ï","ñ","ò","ô","­","ø","õ","ö","÷","ù","ý","ú","û","ü","þ","®","¸","#µ","¶","·","¹","¡","¾","»","¼","½","Æ","¢","Ê","Ç","È","É","Ë","Ð","Ì","Î","Ï","Ñ","£","Õ","Ò","Ó","Ô","Ö","Ý","×","Ø","Ü","Þ","ã","ß","á","â","ä","¤","è","å","æ","ç","é","¥","í","ê","ë","ì","î","ó","ï","ñ","ò","ô","¦","ø","õ","ö","÷","ù","ý","ú","û","ü","þ","§");
    	for($i =0; $i <sizeof($uniChars); $i ++){
			$outputText = str_replace($uniChars[$i], $tcvnChars[$i], $inputText);
		}	
		return 	$outputText; 
    }
    /*
     * @author: Trinh Thanh Phuong
     * Ham phan trang
     * @param unknown_type $iTotalRecord
     * @param unknown_type $iRowOnPage
     */
    function paging($iTotalRecord, $iPage, $iRowOnPage){
    	$htmlpaging  ='<div id = "paging-content">';
    	$iNumberPage  = ceil($iTotalRecord/$iRowOnPage);     //Tong so trang
		$inumberpageinsheet = 10; 						 	 //so trang hien thi
		$iStartPage	  = 1;								     //Trang dau tien
		$iEndpage	  = 1;								 	 //Trang cuoi cung
		$iaddPage	  = 4;									 //buoc tien cua phan trang
		if($iNumberPage < $inumberpageinsheet){
			$iStartPage   = 1;
			$iEndpage	  = $iNumberPage;
		}else{
			if($iPage > $iaddPage){
				$flag = 0;
				while ($iaddPage >= 0){
					if($iNumberPage - ($iPage - $iaddPage -1) >= $inumberpageinsheet){
						$iStartPage = $iPage - $iaddPage;
						$flag = 1;
						break;
					}
					$iaddPage--;
				}
				if (!$flag)
					$iStartPage   = ($iNumberPage - $inumberpageinsheet) + 1;
			}else{
				$iStartPage = 1;
			}
			$iEndpage = ($iStartPage + $inumberpageinsheet) - 1;
		}
		if($iPage > 1){
			$htmlpaging .='<a class = "pre" onclick ="gotopage('.($iPage - 1 ).')">Trước</a>';
		}
		if($iTotalRecord > $iRowOnPage)
			for($i = $iStartPage; $i <= $iEndpage; $i++){
				if($i == $iPage)
					$htmlpaging .='<a class = "pg current" onclick ="gotopage('.$i.')">'.$i.'</a>';
				else $htmlpaging .='<a class = "pg" onclick ="gotopage('.$i.')">'.$i.'</a>';
			}
		if($iPage < $iNumberPage){
			$htmlpaging .='<a class = "nex" onclick ="gotopage('.($iPage + 1 ).')">Tiếp</a>';
		}
    	$htmlpaging  .='</div>';
    	return $htmlpaging;
    }
 	/*
     * @author: Trinh Thanh Phuong
     * Ham phan trang
     * @param unknown_type $iTotalRecord
     * @param unknown_type $iRowOnPage
     */
    function pagingModal($iTotalRecord, $iPage, $iRowOnPage){
    	$htmlpaging  ='<div id = "paging-content-modal">';
    	$iNumberPage  = ceil($iTotalRecord/$iRowOnPage);     //Tong so trang
		$inumberpageinsheet = 10; 						 	 //so trang hien thi
		$iStartPage	  = 1;								     //Trang dau tien
		$iEndpage	  = 1;								 	 //Trang cuoi cung
		$iaddPage	  = 4;									 //buoc tien cua phan trang
		if($iNumberPage < $inumberpageinsheet){
			$iStartPage   = 1;
			$iEndpage	  = $iNumberPage;
		}else{
			if($iPage > $iaddPage){
				$flag = 0;
				while ($iaddPage >= 0){
					if($iNumberPage - ($iPage - $iaddPage -1) >= $inumberpageinsheet){
						$iStartPage = $iPage - $iaddPage;
						$flag = 1;
						break;
					}
					$iaddPage--;
				}
				if (!$flag)
					$iStartPage   = ($iNumberPage - $inumberpageinsheet) + 1;
			}else{
				$iStartPage = 1;
			}
			$iEndpage = ($iStartPage + $inumberpageinsheet) - 1;
		}
		if($iPage > 1){
			$htmlpaging .='<a class = "pre" onclick ="gotopageModal('.($iPage - 1 ).')">Trước</a>';
		}
		if($iTotalRecord > $iRowOnPage)
			for($i = $iStartPage; $i <= $iEndpage; $i++){
				if($i == $iPage)
					$htmlpaging .='<a class = "pg current" onclick ="gotopageModal('.$i.')">'.$i.'</a>';
				else $htmlpaging .='<a class = "pg" onclick ="gotopageModal('.$i.')">'.$i.'</a>';
			}
		if($iPage < $iNumberPage){
			$htmlpaging .='<a class = "nex" onclick ="gotopageModal('.($iPage + 1 ).')">Tiếp</a>';
		}
    	$htmlpaging  .='</div>';
    	return $htmlpaging;
    }
	/*
	 * @author: Trinh Thanh Phuong
     * Ham hien thi chon so ban ghi tren trang
     * @param unknown_type $iTotalRecord
     * @param unknown_type $iRowOnPage
	 */
	public static function _generateChangeRecordNumberPageModal($piValue, $sLabel = ""){		
		$psHtmlString = "";	
		//Chuyen doi thong tin trong xau XML -> Mang
		$arrListItem = Efy_Function_RecordFunctions::getAllObjectbyListCode('',DM_SO_HS_TREN_TRANG);		
		//Tao chuoi HTML
		$psHtmlString = $psHtmlString . "Hiển thị ";
		$psHtmlString = $psHtmlString . "<select class='textbox' id = 'cbo_nuber_record_page_modal' name='cbo_nuber_record_page_modal' optional='true' style='width:60' onChange='changeNumberRowPerPageModal(this)' >";
		$psHtmlString = $psHtmlString . Efy_Library::_generateSelectOption($arrListItem, 'C_CODE', 'C_CODE', 'C_NAME', $piValue);
		$psHtmlString = $psHtmlString . "</select>";
		$strlabel = '';	
		if ($sLabel != ""){
			$strlabel = " $sLabel/1 trang";
		}else{
			$strlabel = " hồ sơ/1 trang";
		}
		$psHtmlString = $psHtmlString . $strlabel;		
		return $psHtmlString;
	}
	
	public static function _getAllFileJavaScriptCssArray($psModuleName,$psModuleNameOrther = "" ,$parrFileName = "",$psDelimitor = ",",$psExtension,$result=array()){		
		// Duong dan thu muc doc file
		$sDir = null;		
		// chuoi ket qua tra ve
		$sResHtml = null;
		
		Zend_Loader::loadClass('Efy_Init_Config');
		
		$objInitConfif  = new Efy_Init_Config();
		
		//
		$filetype = strtolower($psExtension);
		
		// thuc hien lay tren tung module cu the
		if($psModuleName != ""){
			//
			$sDir = $psModuleName.'/';		
			
			if (is_dir($sDir)) {				
			    if ($dh = opendir($sDir)) {
			    	$i = sizeof($result);
			        while (($file = readdir($dh)) !== false) {			        			 
			        	//Thuc hien include file JavaScript	
			        	$filetypeinDirJs = substr($file,strlen($file)-2,2);			        	
		        		$filetypeinDirJs = strtolower($filetypeinDirJs);		        	
			        			        	
			        	if($filetype == "js" && $filetypeinDirJs =="js" ){		
			        		$sDirFull = $objInitConfif->_setWebSitePath().$sDir.$file;
			        		$result[$i]['type'] ='js';	        		
			        		$result[$i]['src'] =$sDirFull;
			        	}	
			        	
			        	//Thuc hien include file Css
			        	$filetypeinDirCss = substr($file,strlen($file)-3,3);			        	
		        		$filetypeinDirCss = strtolower($filetypeinDirCss);	
			        	if($filetype == "css" && $filetypeinDirCss =="css"){			        		
			        		$sDirFull = $objInitConfif->_setWebSitePath().$sDir.$file;
			        		$result[$i]['type'] ='css';	        		
			        		$result[$i]['src'] =$sDirFull;          	
			        	}
			        	$i++;	
			        }
			        closedir($dh);
			    }
			}
		}
		$count = sizeof($result);
		// Thuc hien lay file js o nhung module khac		
		if($psModuleNameOrther!= ""){
			//
			$sDir =  $psModuleNameOrther .'/';
			//			
        	$arrTemp = explode($psDelimitor,$parrFileName);
        	
        	for($index =0 ; $index < sizeof($arrTemp); $index++){

        		//Thuc hien include file JavaScript	
	        	$filetypeinDirJs = @substr($arrTemp[$index],strlen($file)-2,2);			        	
        		$filetypeinDirJs = @strtolower($filetypeinDirJs);		        		
	        	if($filetype == "js" && $filetypeinDirJs =="js" ){				        		
	        		$sDirFull = $objInitConfif->_setLibUrlPath().$sDir.$arrTemp[$index];
	            	$result[$count]['type'] ='js';	        		
			        $result[$count]['src'] =$sDirFull;             	
	        	}	
	        	
	        	//Thuc hien include file Css
	        	$filetypeinDirCss = @substr($arrTemp[$index],strlen($file)-3,3);			        	
        		$filetypeinDirCss = @strtolower($filetypeinDirCss);	
	        	if($filetype == "css" && $filetypeinDirCss =="css"){			        		
	        		$sDirFull = $objInitConfif->_setLibUrlPath().$sDir.$arrTemp[$index];
	        		$result[$count]['type'] ='css';	        		
			        $result[$count]['src'] =$sDirFull;  
	        	}	
	        	$count++;
        	}		

		}
		return $result;
	}
	/**
	 * @author:TuanPM
	 * @see: 28/12/2012
	 * @todo: convert chu tieng viet co dau sang khong dau
	 * Enter description here ...
	 */
	public static function _Replace_VietNamese($str) {
	     $str = preg_replace("/(à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ)/i", 'a', $str);
	     $str = preg_replace("/(è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ)/i", 'e', $str);
	     $str = preg_replace("/(ì|í|ị|ỉ|ĩ)/i", 'i', $str);
	     $str = preg_replace("/(ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ)/i", 'o', $str);
	     $str = preg_replace("/(ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ)/i", 'u', $str);
	     $str = preg_replace("/(ỳ|ý|ỵ|ỷ|ỹ)/i", 'y', $str);
	     $str = preg_replace("/(đ)/i", 'd', $str);
	     $str = preg_replace("/(À|Á|Ạ|Ả|Ã|Â|Ầ|Ấ|Ậ|Ẩ|Ẫ|Ă|Ằ|Ắ|Ặ|Ẳ|Ẵ)/", 'A', $str);
	     $str = preg_replace("/(È|É|Ẹ|Ẻ|Ẽ|Ê|Ề|Ế|Ệ|Ể|Ễ)/", 'E', $str);
	     $str = preg_replace("/(Ì|Í|Ị|Ỉ|Ĩ)/", 'I', $str);
	     $str = preg_replace("/(Ò|Ó|Ọ|Ỏ|Õ|Ô|Ồ|Ố|Ộ|Ổ|Ỗ|Ơ|Ờ|Ớ|Ợ|Ở|Ỡ)/", 'O', $str);
	     $str = preg_replace("/(Ù|Ú|Ụ|Ủ|Ũ|Ư|Ừ|Ứ|Ự|Ử|Ữ)/", 'U', $str);
	     $str = preg_replace("/(Ỳ|Ý|Ỵ|Ỷ|Ỹ)/", 'Y', $str);
	     $str = preg_replace("/(Đ)/", 'D', $str);
	     return $str;
     }
     /**
	 * Nguoi tao: tuanpm
	 * Ngay tao: 
	 * Y nghia: Lay danh sach chuc vu -  ten cua danh sach id cac can bo khi truyền vào một danh sách cán bộ
	 */	
	public static function _getStaff($arrStaff, $arrPkStaff){
		$countStaff = sizeof($arrStaff);
		$countPkStaff = sizeof($arrPkStaff);
		$strStaff = '';
		for($i = 0; $i < $countPkStaff; $i++)
			for($j = 0; $j < $countStaff; $j++)
				if($arrPkStaff[$i] == $arrStaff[$j]['id'])
					$strStaff = $strStaff.','.$arrStaff[$j]['position_code'].' - '.$arrStaff[$j]['name'];
		$strStaff = substr($strStaff,1,strlen($strStaff));
		return $strStaff;
	}
	/*
	 * @author:TuanPM
	 * @see: 28/12/2012
	 * @todo: Tu dong sinh C_CODE
	 * Enter description here ...
	 */
	public static function _getCode($arrTree, $Pk_Tree){
		$tmp = 0;
		for ($i = 0; $i < sizeof($arrTree); $i++){
			if( $arrTree[$i]['FK_OBJECT'] ==  $Pk_Tree)
				$tmp++;
		}
		if ($tmp < 10) $tmp = '0'.$tmp;
		return $tmp;
	}
	/*
	 * @author:TuanPM
	 * @see: 28/12/2012
	 * @todo: Load cac node con khi click vao node do
	 * Enter description here ...
	 */
	public function _getChildNode($idNode,$arrTreeGetAll){
		$arrOutput = array();
		foreach ($arrTreeGetAll as $key => $value) {
			if($value['FK_OBJECT'] == $idNode){
				array_push($arrOutput, array('attr'=>array(
												'id'=>$value['PK_OBJECT']
												,'rel'=>'folder'
											),
											'data'=>$value['TR04'],
											'state'=>'closed'
				));
			}
		}
		return $arrOutput;
	}
	public static function _setColCode_Name($variable,$boolen){
		foreach ($variable as $key => $value) {
			if ($boolen == 'true')
				$variable[$key]['name'] = $variable[$key]['position_code'].' - '. $variable[$key]['name'];
			else $variable[$key]['name'] = $variable[$key]['name'];
		}
		return $variable;
	}

	public function parseAttachFile($strFileList, $deliFileList = '!#~$|*', $deliFileName = '!~!', $sPathLink){
		
		$strFileName = explode($deliFileList,$strFileList);		
		$fileAttach = '';
		$images = array();	
		$videos = array();
		$documents = array();
		for($i =0; $i < sizeof($strFileName); $i ++){
			$arrFileName = explode($deliFileName,$strFileName[$i]);			
			$fileName    = $arrFileName[1];
			$fileID 	 = $arrFileName[0];
			$arrFileLink = explode('_',$fileID);
			$fileLink = $sPathLink . $arrFileLink[0] . "/" . $arrFileLink[1] . "/" . $arrFileLink[2] . "/" . $strFileName[$i];

			$pathFileExist = '..' . str_replace("/","\\",$fileLink);			
			if(file_exists($pathFileExist)){
				$fileExtensiona = explode('.', $fileName);
				$fileExtension = end($fileExtensiona);
				$arrTemp = array('link'=>$fileLink,'name'=>$fileName);
				switch ($this->checktype($fileExtension)) {
					case 'image':
						array_push($images,$arrTemp);
						break;
					case 'video':
						array_push($videos,$arrTemp);
						break;
					default:
						array_push($documents,$arrTemp);
						break;
				}
			}
			// 
		}
		return array(
					'images'=>$images
					,'videos'=>$videos
					,'documents'=>$documents
				);
	}
	private function checktype($type){
		$type = strtoupper($type);

		switch ($type) {
			case 'JPG':
			case 'PNG':
			case 'JPEG':
			case 'GIF':
				$check = 'image';
				break;
			case 'MP4':
			case 'FLV':
			case 'MOV':
			case 'MPEG':
			case 'WMV':
			case 'AVI':
			case 'DIVX':
			case 'XVID':
			case 'RM':
			case 'RMVB':
            case 'M4V':
            case 'WEBM':
				$check = 'video';
				break;
			default:
				$check = 'document';
				break;
		}
		return $check;
	}

	public function genfilmstripimage($images){

		$string ='';
		$string .= '<div id="gallery" class="ad-gallery">';
		$string .= '<ul class="ad-thumb-list">';
		foreach ($images as $key => $image) {


			$string .= '<li class="imgli">';
			$string .= '<a href="'.$image['link'].'" rel="lightbox-group1">';
			$string .= '<img width="150" height="150" src="'.$image['link'].'" class="imagefilm" title="'.$image['name'].'">';
			$string .= '<label title="'.$image['name'].'">'.$this->shorttitle($image['name'],20).'</label>';
			$string .= '</a>';
			$string .= '</li>';
		}
		$string .= '</ul>';
		$string .= '</div>';
		return $string;
	}

	public function genfilmstripdocument($documents){
		
		$objconfig = new Efy_Init_Config();
		$srcword = $objconfig->_setImageUrlPath().'word-small.gif';
		$srcpdf = $objconfig->_setImageUrlPath().'pdf-small.gif';
		$srcxls = $objconfig->_setImageUrlPath().'xls-small.gif';
		$srcppt = $objconfig->_setImageUrlPath().'ppt-small.png';
        $srcunknow = $objconfig->_setImageUrlPath().'unknown-small.png';

		$string ='';
		$string .= '<div style="padding-bottom:20px;">';
		foreach ($documents as $key => $document) {
			$arr = explode('/', $document['link']);
			$filenamefull = end($arr);
			$arr = explode('.', $document['link']);
			$type = end($arr);
			$type = strtolower($type);
			switch ($type) {
				case 'xls':
				case 'xlsx':
				case 'XLS':
				case 'XLSX':
                    $flag= 1;
					$src = $srcxls;
					break;
				case 'ppt':
				case 'pptx':
				case 'PPT':
				case 'PPTX':
                    $flag= 1;
					$src = $srcppt;
					break;
					
				case 'pdf':
				case 'PDF':
                    $flag= 1;
					$src = $srcpdf;
					break;
                case 'doc':
                case 'DOC':
                case 'docx':
                case 'DOCX':
                    $flag= 1;
                    $src = $srcword;
                    break;
                default:
                    $flag= 0;
                    $src = $srcunknow;
                    break;
			}
			$string .= '<div class="shortdesc">';
            $string .= '<a href="#" onclick="{readdocument(\''.$filenamefull.'\')}"><img alt="Word-logo-small" src="'.$src.'"></a>';
            $string .= '<div>';
            // $string .= '<h3 class= "document_view">'.$document['name'].'<a href="'.$document['link'].'" target="_blank"> ( Tải về )</a></h3>';
            // shtml += '<img width="150" height="100" src="'+ data[i]['C_FILENAME_THUMB'] + '">';

            // download.png
            $string .= '<h3 class= "document_view">'.$document['name'].'<a href="#" class="download" onclick="showmodallogin()"> </a></h3>';
            $string .= '<div id="preview-doc"></div>';
	    	$string .= '</div></div>';
		}
		$string .= '</div>';
		return $string;
	}

	public function genfilmstripvideo($videos){
		
		$objconfig = new Efy_Init_Config();
		$scr = $objconfig->_setAttachFileUrlPath().'/default/player.gif';
		$string ='';
		$string .= '<div>';
		$string .= '<ul class="ad-thumb-list">';
		foreach ($videos as $key => $video) {

			$string .= '<li class="imgli strigvideo">';
			$string .= '<img width="150" height="150" src="'.$scr.'" class="imagefilm" title="'.$video['name'].'">';
			$string .= '<label class="normal_label" title="'.$video['name'].'">'.$this->shorttitle($video['name'],20).'</label>';
			// $string .= '<a class="attach-file jpg" href="'.$video['link'].'" alt="">'.$video['name'].'</a>';
			$string .= '</li>';


		}
		$string .= '</ul>';
		$string .= '</div>';
		return $string;
	}

	public function shorttitle($title,$max){
		if(strlen($title) > $max){
			if($title[$max] !=''){
				for ($i = $max; $i > 0 ; $i--) { 
					if(trim($title[$i]) =='')
						return substr($title, 0,$i).'...';
				}
			}
			$title = substr($title, 0,$max).'...';
		}
		return $title;
	}

	public function getDataTree($arrTreeGetAll)
	{
		$arrTemp = array();
		$idNode = null;
		foreach ($arrTreeGetAll as $key => $value) {			
			if(is_null($value['FK_OBJECT'])){
				$idNode = $value['PK_OBJECT'];
			}else{
				array_push($arrTemp, $value);
			}
		}
		$arrDefault = array();
		foreach ($arrTemp as $key => $value) {
			if($value['FK_OBJECT'] == $idNode){
				array_push($arrDefault, $value['PK_OBJECT']);
			}
		}
		

		$datatree = array();
		$arrResult = array();
		foreach ($arrDefault as $key => $value) {
			$dataNode = array();			
			$dataNode = $this->getnode($arrTemp,$value);
			$this->getChild($arrTemp,$value,$dataNode);
			array_push($datatree, $dataNode);
		}

		return array(
			'dataTree'=>$datatree
			,'nodeDefault'=>$arrDefault
			);
	}

	public function setsessiontree(){
		$objDb	= new Efy_DB_Connection();
		$ownerCode = $_SESSION['OWNER_CODE'];
		$arrParameter = array(
			'status'=>'HOAT_DONG'
			,'txtFullTextSearch'=>''
			,'type'=>'TRAINING'
			,'sOwner_code'=>$ownerCode
			,'staff_id'=> $_SESSION['staff_id']
		);	
		// Tranning
		// $arrParameter['type'] = 'TRAINING';
		$arrData = $objDb->mTLSPRun('mTL_TreeGetAll',$arrParameter,1,0);
		$arrData =  $this->getDataTree($arrData);
		$_SESSION['TREE_TRAINING'] = $arrData['dataTree'];
		$_SESSION['NODE_DEFAULT_TRAINING'] = $arrData['nodeDefault'];
	}
	public function checkdatatree(){
		if(isset($_SESSION['TREE_TRAINING']) && isset($_SESSION['TREE_LEARNING']))
			return true;
		// Set gia tri
		$this->setsessiontree();
		$position_code = $this->_getItemAttrById($_SESSION['arr_all_staff'],$_SESSION['staff_id'],'position_code');
		$StaffName = $this->_getItemAttrById($_SESSION['arr_all_staff'],$_SESSION['staff_id'],'name');
		$_SESSION['position_name'] = $position_code.' - '.$StaffName; 
		return true;
	}
	//Lay thong tin cua 1 Node
	public function getnode(&$datas,$idNode){
		$dataTemp = array();
		foreach ($datas as $key => $data) {
			if($data['PK_OBJECT'] == $idNode){
				$dataTemp = array(
						'data'=>$data['TR04']
						// ,'id'=>$idNode
						,'metadata'=> array('id'=>$idNode)
						,'attr'=> array('id'=>$idNode,'href'=>'#' )
						,'children'=>array()
					);
				unset($datas[$key]);
				return $dataTemp;
			}
		}
	}
	//Lay thong tin các child cua 1 Node
	public function getChild($datas,$idNode,&$datatree){
		if(is_null($idNode) || $idNode ==''){
			return true;
		}
		$arrChild = array();
		$arrTemp = array();
		foreach ($datas as $key => $data) {
			if($data['FK_OBJECT'] == $idNode)
				array_push($arrChild, $data['PK_OBJECT']);
		}
		if($arrChild){
			foreach ($arrChild as $key => $child) {
				array_push($arrTemp, $this->getnode($datas,$child));
			}
			
			for ($i=0; $i < sizeof($arrChild); $i++) { 
				$this->getChild($datas,$arrChild[$i],&$arrTemp[$i]);
			}
			$datatree['children'] = $arrTemp;
		}
	}
	public static function _generate_day_of_week($p_lang){
		$RetStr = date("l, d/m/y");
		$pday = date("l");
		if($p_lang == 1){
			switch($pday){
				case "Sunday";
					$RetStr = "Ch&#7911; nh&#7853;t";
					break;
				case "Monday";
					$RetStr = "Th&#7913; hai";
					break;
				case "Tuesday";
					$RetStr = "Th&#7913; ba";
					break;
				case "Wednesday";
					$RetStr = "Th&#7913; t&#432;";
					break;
				case "Thursday";
					$RetStr = "Th&#7913; n&#259;m";
					break;
				case "Friday";
					$RetStr = "Th&#7913; s&#225;u";
					break;
				case "Saturday";
					$RetStr = "Th&#7913; b&#7843;y";
			}
			$RetStr = $RetStr.", ".date("d/m/Y");
		}
		return $RetStr;
	}
	public function _delCookie($sNname){ 
		setcookie($sNname, "", time(),"/",""); 
	}

	public static function checkroles($role, $rolealow) {
		$arrAlow = explode('!@!', $rolealow);
		foreach ($arrAlow as $key => $value) {
			if ($value == $role) {
				return true;
			}
		}
		return false;
	}
	public function setBody($template_file, $params){
		$path = $_SERVER['SCRIPT_FILENAME'];
		$arrPath = explode('/', $path);
		$path = substr($path, 0, (0 -strlen($arrPath[sizeof($arrPath) - 1])));
		$template_file_path = realpath($path).DIRECTORY_SEPARATOR.'templates'.DIRECTORY_SEPARATOR.$template_file;			
		$template_file_content = $this->_readFile($template_file_path);
		$tags = array_keys($params);
		foreach ($tags as $value){
			$template_file_content = str_replace($value, $params[$value], $template_file_content);
		}
		return $template_file_content;
	}
	public function sendEmail($data){
		Zend_Loader::loadClass('Zend_Mail_Transport_Smtp');
		Zend_Loader::loadClass('Zend_Mail');
		$objConfig = new Efy_Init_Config();
		$emails = $objConfig->_getEmail();
		$mailTransport = new Zend_Mail_Transport_Smtp($emails['smtp_host'], $emails);
		Zend_Mail::setDefaultTransport($mailTransport);
		$mail = new Zend_Mail('utf-8');
		$mail->setFrom($emails['username'],$emails['sender_name']);
		$mail->setMessageId();
		$body_data = $data['body_data'];
		$body_data['c_sender_email__'] = $emails['username'];
		$body = $this->setBody($data['template'],$body_data);
		$mail->setBodyHtml($body);
		$mail->addTo($data['email'], $data['name']);
		$mail->setSubject($data['subject']);
		$result = $mail->send();
		return $result;
	}
}?>